import java.util.Scanner; /** Practice using methods that are part of the String class. 1. Declare a String object (reference variable) 2. Read in a String from the keyboard 3. toUpperCase(), toLowerCase() 4. Assignment 5. .equals(str), .equalsIgnoreCase(str) 6. .compareTo(str), compareToIgnoreCase(str) 7. .startsWith(str) and .endsWith(str) NONE OF THESE METHODS MODIFY THE STRING. Most of them are used for comparing Strings. */ public class StringEx { public static void main(String[] args) { String name; // To hold a name // Create a Scanner object for keyboard input. Scanner keyboard = new Scanner(System.in); // Get a name from keyboard System.out.print("Enter a name: "); name = keyboard.nextLine(); //name = name.toUpperCase(); String nameUpper = name.toUpperCase(); System.out.println("Upper case of name is: " + nameUpper); // Assignment of Strings is allowed. name=nameUpper; if (name==nameUpper) // are our addresses equal // are we referring to the same String? System.out.println("These names are equal, name is: " + name); String str3 = "BOB"; if (name==str3) System.out.println("str3 is the same ADDRESS as name."); else System.out.println("str3 is not the same ADDRESS as name."); // use .equals() to compare 2 String objects // .equals() is CASE SENSITIVE if(name.equals(str3)) System.out.println("values of name and str3 are the same."); // let's say you want to alphabetize a list of names // use compareTo(str) method String fruit1="pear"; String fruit2="apple"; // let's get the alphabetical order of our fruits if (fruit1.compareTo(fruit2)<0) // fruit1