//String class provides methods //String method tests import java.util.StringTokenizer; import java.util.ArrayList; public class eg22_StringMethods { public static void main(String[] args) { String str = "Programming is interesting but I am really sleepy."; if (str.startsWith("Programming")) System.out.println("The string starts with Programming."); else System.out.println("The string does not start with Programming."); String str2 = "I really really like Fridays."; System.out.println("str: start = "+str.indexOf("really")); //start position: 36 System.out.println("str2: start = "+str2.indexOf("really")); //start position: 2 if (str.regionMatches(true, 36, str2, 2, 6)) //6 is the length of region to match System.out.println("The regions match."); else System.out.println("The regions does not match."); System.out.println("str2: start = "+str2.lastIndexOf("really")); //start position: 2 String fullName = "Cynthia Susan Lee"; String middleName = fullName.substring(8,13); //start position; end position System.out.println("The full name is " + fullName); System.out.println("The full name is " + middleName); System.out.println(); //String concat method does the same thing as +, so it is skipped //replace method, replace a character by another character String str1 = "Tom Talber Tried Trains"; System.out.println(str1); //before replace str1 = str1.replace('T','D'); System.out.println(str1); //after replace System.out.println(); //replace method, can also replace substring str1 = "Tom Talber Tried Trains and Trains"; System.out.println(str1); //before replace str1 = str1.replace("Trains","Domains"); System.out.println(str1); //after replace System.out.println("length of string = "+str.length()); for (int i=0; i list = new ArrayList(); //this one gives error because ArrayList expects objects ArrayList list = new ArrayList(); //this is OK Integer myInt1 = 5; list.add(myInt1); //Autoboxing int primitiveNumber1 = list.get(0); //Unboxing } }