/* this demonstrates how to compare Strings */ public class stringcomp { public static void main(String args[]) { String Student1 = new String("Jake"); String Student2 = new String("Jake"); System.out.println("Student1 is actually "+System.identityHashCode(Student1)); System.out.println("Student2 is actually "+System.identityHashCode(Student2)); // Lets try comparing them with the equality operator if(Student1 == Student2) { System.out.println("These are the same object."); } else { System.out.println("These are not the same object."); } // Hmm, that didn't work, lets try using the equals() method if(Student1.equals(Student2)) { System.out.println("These Strings are equal."); } else { System.out.println("These Strings are not equal."); } } }