-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatpt.java
More file actions
71 lines (51 loc) · 2.15 KB
/
Chatpt.java
File metadata and controls
71 lines (51 loc) · 2.15 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
67
68
69
70
71
public class Chatpt {
public static void main(String[] args) {
String str = "hello wirld!";
String str2 = "HELLO WIRLD!";
String str3 = "hello";
// length()
System.out.println("Length: " + str.length());
// charAt()
System.out.println("Character at index 1: " + str.charAt(1));
// substring(i)
System.out.println("Substring from index 6: " + str.substring(6));
// substring(i, j)
System.out.println("Substring from 0 to 5: " + str.substring(0, 5));
// concat()
System.out.println("Concat: " + str.concat(" Welcome"));
// indexOf()
System.out.println("Index of 'o': " + str.indexOf("o"));
// indexOf(s, i)
System.out.println("Index of 'o' from index 5: " + str.indexOf("o", 5));
// lastIndexOf()
System.out.println("Last index of 'l': " + str.lastIndexOf("l"));
// equals()
System.out.println("Equals 'hello wirld!': " + str.equals("hello wirld!"));
// equalsIgnoreCase()
System.out.println("Equals Ignore Case: " + str.equalsIgnoreCase(str2));
// compareTo()
System.out.println("CompareTo 'hello': " + str.compareTo(str3));
// compareToIgnoreCase()
System.out.println("CompareTo Ignore Case: " + str.compareToIgnoreCase(str2));
// toLowerCase()
System.out.println("Lowercase: " + str.toLowerCase());
// toUpperCase()
System.out.println("Uppercase: " + str.toUpperCase());
// trim()
String strWithSpace = " hello wirld! ";
System.out.println("Trim: '" + strWithSpace.trim() + "'");
// replace()
System.out.println("Replace 'i' with 'o': " + str.replace('i', 'o'));
// contains()
System.out.println("Contains 'wirld': " + str.contains("wirld"));
// toCharArray()
char[] arr = str.toCharArray();
System.out.print("Char Array: ");
for(char c : arr) {
System.out.print(c + " ");
}
System.out.println();
// startsWith()
System.out.println("Starts with 'hello': " + str.startsWith("hello"));
}
}