-
Notifications
You must be signed in to change notification settings - Fork 28
/
Strings.java
48 lines (46 loc) · 1.42 KB
/
Strings.java
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
47
48
public class Strings{
public static void main(String args[]){
// String name1="Tony";
// String name2="Tony";
// if(name1.equals(name2))
// {
// System.out.println("Strings are equal");
// }
// else{
// System.out.println("Strings are unequal");
// }
// if(name1==name2){
// System.out.println("Strings are equal");
// }
// else{
// System.out.println("Strings are unequal");
// }
// don't use == for string equality check, it only checks for length
// if(new String("Trony")==new String("Trony")){ // can also define string like this
// System.out.println("Same string");
// }
// else{
// System.out.println("Different string");
// }
/*Accessing character of a string
String firstName = "Tony";
String secondName = "Stark";
String fullName = firstName + " " + secondName;
for(int i=0; i<fullName.length(); i++) {
System.out.println(fullName.charAt(i));
}
*/
/*substring
String name = "TonyStark";
System.out.println(name.substring(0, 4));
*/
//integer to string
// String str = "123";
// int number = Integer.parseInt(str);
// System.out.println(number);
int number = 123;
String str = Integer.toString(number);
System.out.println(str);
// strings are immutable in java
}
}