-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringMethods1.java
More file actions
35 lines (26 loc) · 988 Bytes
/
Copy pathStringMethods1.java
File metadata and controls
35 lines (26 loc) · 988 Bytes
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
/*Write programs for implementation of different
methods of:
String class.
StringBuffer class.*/
public class StringMethods1 {
public static void main(String[] args) {
String str = "Hello World";
System.out.println(str);
// length()
System.out.println("Length: " + str.length());
// toUpperCase()
System.out.println("Uppercase: " + str.toUpperCase());
// toLowerCase()
System.out.println("Lowercase: " + str.toLowerCase());
// charAt()
System.out.println("Character at index 4: " + str.charAt(4));
// substring()
System.out.println("Substring (0 to 5): " + str.substring(0, 5));
// indexOf()
System.out.println("Index of 'o': " + str.indexOf('o'));
// equals()
System.out.println("Equals 'Hello World': " + str.equals("Hello World"));
// contains()
System.out.println("Contains 'World': " + str.contains("World"));
}
}