-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.java
More file actions
54 lines (38 loc) · 1.91 KB
/
string.java
File metadata and controls
54 lines (38 loc) · 1.91 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
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;
public class string {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Welcome to String Modules & Methods");
System.out.println("Enter the User Input : ");
String userString = input.nextLine(); // Sujit
System.out.println(userString.length()); // 5
System.out.println(userString.charAt(0)); // S
System.out.println(userString.equals("Sujit")); // ture
System.out.println(userString.equalsIgnoreCase("sujit")); // true
System.out.println(userString.contains("Su")); // true
System.out.println(userString.substring(1, 3)); // uj - i not mention because last index not include
System.out.println(userString.indexOf("S")); // 0
System.out.println(userString.replace("Su", "A")); // Ajit
System.out.println(userString.toUpperCase()); // SUJIT
System.out.println(userString.toLowerCase()); // sujit
// -----------------------------------------------------
String name = " Sujit ";
System.out.println(name.trim()); // Sujit - remove extra space
// ---------------------------------------------------------------
String[] arr = userString.split(" ");
System.out.println(arr);
for(String word : arr){
System.out.println(word); // Sujit
}
System.out.println(Arrays.toString(arr)); // [Sujit]
/*
Feature String StringBuffer StringBuilder
Mutable No Yes Yes
Storage String Constent pool heap heap
Thread Safe Yes Yes No
Speed Slow Medium Fast
*/
}
}