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
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
1public char charAt(int index)
2-----------------------------
3String x = "airplane";
4System.out.println( x.charAt(2) ); // output is 'r'
5
1public int length()
2-----------------------
3String x = "01234567";
4System.out.println( x.length() ); // returns "8"
5
1public String concat(String s)
2
3String x = "book";
4System.out.println( x.concat(" author") ); // output is "book author"
5
1public String trim()
2
3String x = " hi ";
4System.out.println( x + "x" ); // result is" hi x"
5System.out.println(x.trim() + "x"); // result is "hix"
6