-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringMethods.java
More file actions
64 lines (45 loc) · 1.74 KB
/
StringMethods.java
File metadata and controls
64 lines (45 loc) · 1.74 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
package com.company;
import java.util.Locale;
public class StringMethods {
public static void main(String[] args) {
String name = " Abhayay ";
// 1. lengrh of name
System.out.println(name.length());
// 2. lower case name
System.out.println(name.toLowerCase(Locale.ROOT));
// 3. upper case name
System.out.println(name.toUpperCase());
// 4. trim name
System.out.println(name.trim());
// 5. substrung name
System.out.println(name.substring(6));
// 6. substrung name beg and end
System.out.println(name.substring(5,10));
// 7. replace char name
System.out.println(name.replace("y" , "a"));
System.out.println(name.replace("ay" , "ya"));
// 8. starts with or not
String name2 = "Abhay";
System.out.println(name2.startsWith("A"));
System.out.println(name2.startsWith("b"));
// 9. end with or not
System.out.println(name2.endsWith("y"));
System.out.println(name2.endsWith("a"));
// 10. char index
System.out.println(name.charAt(5));
// 11. index char
System.out.println(name.indexOf("h"));
// 12. index char from
System.out.println(name.indexOf("h" , 3));
// 13. index from end
System.out.println(name.lastIndexOf("y"));
// 14. index from end
System.out.println(name.lastIndexOf("y" , 7));
// 15. equall to name
System.out.println(name.equals(" Abhayay "));
System.out.println(name.equals(" abhayay "));
// 16. equall withoit case
System.out.println(name.equalsIgnoreCase(" abhayay "));
System.out.println(name.equalsIgnoreCase("abhay"));
}
}