1public boolean equalsIgnoreCase(String s)
2------------------------------------------
3String x = "Exit";
4System.out.println( x.equalsIgnoreCase("EXIT")); // is "true"
5System.out.println( x.equalsIgnoreCase("tixe")); // is "false"
6
1static String valueOf(int i) - returns the string representation of the int
2argument.
1public boolean contains(“searchString”)
2
3String x = “Java is programming language”;
4System.out.println(x.contains(“Amit”)); // This will print false
5System.out.println(x.contains(“Java”)); // This will print true
6
1// all String methods
2public class StringMethodsDemo {
3 public static void main(String[] args) {
4 String targetString = "Java is fun to learn";
5 String s1= "JAVA";
6 String s2= "Java";
7 String s3 = " Hello Java ";
8
9 System.out.println("Char at index 2(third position): " + targetString.charAt(2));
10 System.out.println("After Concat: "+ targetString.concat("-Enjoy-"));
11 System.out.println("Checking equals ignoring case: " +s2.equalsIgnoreCase(s1));
12 System.out.println("Checking equals with case: " +s2.equals(s1));
13 System.out.println("Checking Length: "+ targetString.length());
14 System.out.println("Replace function: "+ targetString.replace("fun", "easy"));
15 System.out.println("SubString of targetString: "+ targetString.substring(8));
16 System.out.println("SubString of targetString: "+ targetString.substring(8, 12));
17 System.out.println("Converting to lower case: "+ targetString.toLowerCase());
18 System.out.println("Converting to upper case: "+ targetString.toUpperCase());
19 System.out.println("Triming string: " + s3.trim());
20 System.out.println("searching s1 in targetString: " + targetString.contains(s1));
21 System.out.println("searching s2 in targetString: " + targetString.contains(s2));
22
23 char [] charArray = s2.toCharArray();
24 System.out.println("Size of char array: " + charArray.length);
25 System.out.println("Printing last element of array: " + charArray[3]);
26
27 }
28
29}
30
31
1public String substring(int begin)/ public String substring(int begin, int end)
2------------------------------------------------------------------------------
3String x = "0123456789"; // the value of each char is the same as its index!
4System.out.println( x.substring(5) ); // output is "56789"
5System.out.println( x.substring(5, 8)); // output is "567"
6
1String txt = "Hello World";
2System.out.println(txt.toUpperCase()); // Outputs "HELLO WORLD"
3System.out.println(txt.toLowerCase()); // Outputs "hello world"
4