-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStringIntro.java
More file actions
46 lines (42 loc) · 1.5 KB
/
StringIntro.java
File metadata and controls
46 lines (42 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package strings;
public class StringIntro {
public static void main(String[] args) {
// creating a string using string literal
String str = "Hello World!";
// creating a string using new keyword
String st = new String("Hi, I am Subhakanta.");
System.out.println(str);
System.out.println(st);
// System.out.println(str.hashCode());
// System.out.println(st.hashCode());
// String smr = new String("Hello World!"); //"hello World!"; //st; //str.concat(st);
// System.out.println(smr.hashCode());
// concatenation of strings
/*
* 1. using String concat() method [String.concat(String)]
* 2. using + operator [String1 + String2]
* */
String strts = str.concat(st);
System.out.println(strts);
strts = st + str + 1;
System.out.println(strts);
// compare Strings
/*
* three ways to compare
* 1. using equals() method [boolean equals(string)]
* 2. using == operator
* 3. using compareTo() method
* */
String str2 = new String("iello World!");
String str3 = new String("Hello World!");
String str4 = "hello world!!";
System.out.println(str2.equals(str));
boolean b = str.equals("Hello World!");
System.out.println(b);
str3 = str2;
boolean bn = (str3 == str2);
System.out.println(bn);
int val = str2.compareTo(str4);
System.out.println(val);
}
}