forked from naveenanimation20/JavaSessionsCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringManipulation.java
More file actions
66 lines (46 loc) · 1.7 KB
/
StringManipulation.java
File metadata and controls
66 lines (46 loc) · 1.7 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package JavaSessions;
public class StringManipulation {
public static void main(String[] args) {
String s = "The rains have started here selenium";
System.out.println(s.length());
System.out.println(s.charAt(5));
System.out.println(s.charAt(26));
//System.out.println(s.charAt(27));//StringIndexOutOfBoundsException
System.out.println(s.indexOf('a'));
System.out.println(s.indexOf('s'));//8 -- 1st occurrence of s
System.out.println(s.indexOf('s', s.indexOf('s')+1));//15 -- 2nd occurrence of s
System.out.println(s.indexOf('s', s.indexOf('s', s.indexOf('s')+1)+1));//15 -- 3rd occurrence of s
System.out.println(s.indexOf("have"));
System.out.println(s.indexOf("hello")); //-1
String s1 = "The rains Have started here";
System.out.println(s.equals(s1));
System.out.println(s.equalsIgnoreCase(s1));
//trim:
String str = " Hello World ";
System.out.println(str.trim());
//replace:
String date = "01-01-2018"; //01/01/2018
System.out.println(date.replace('-', '/'));
String s3 = "Hello World";
System.out.println(s3.replace(" ",""));
//sub string:
String s4 = "The rains have started here";
System.out.println(s4.substring(0, 9));
//split:
String s5 = "Hello_Selenium_Testing";
String arr[] = s5.split("_");
System.out.println(arr[0]);
System.out.println(arr[1]);
System.out.println(arr[2]);
String h = "XxTestXxTestXxXtesting";
String d[] = h.split("Xx");
for(int i=0; i<d.length; i++){
System.out.println(i+"-->"+d[i]);
}
String firstName = "Tom;Naveen;Felix;Ipsi;Sharmi";
String firstName1[] = firstName.split(";");
for(int i=0; i<firstName1.length; i++){
System.out.println(firstName1[i]);
}
}
}