public class StringComparison { 

  public static void main(String[] args) { 
    String str1 = "FooBar";
    String str2 = str1;
    String str3 = new String("FooBar");
    String str4 = "FooBar";
    String str5 = "Foo" + "Bar";
    String str6 = new String("Foo") + new String("Bar");

    System.out.println("str1 == str2: " + (str1 == str2));  
    System.out.println("str1 == str3: " + (str1 == str3));  
    System.out.println("str1 == str4: " + (str1 == str4));  
    System.out.println("str1 == str5: " + (str1 == str5));  
    System.out.println("str1 == str6: " + (str1 == str6));  
    System.out.println("str1.equals(str2): " + str1.equals(str2));
    System.out.println("str1.equals(str3): " + str1.equals(str3));
    System.out.println("str1.equals(str4): " + str1.equals(str4));
    System.out.println("str1.equals(str5): " + str1.equals(str5));
    System.out.println("str1.equals(str6): " + str1.equals(str6));
    System.out.println("str1.compareTo(str2): " + str1.compareTo(str2)); 
    System.out.println("str1.compareTo(str3): " + str1.compareTo(str3)); 
    System.out.println("str1.compareTo(str4): " + str1.compareTo(str4)); 
    System.out.println("str1.compareTo(str5): " + str1.compareTo(str5)); 
    System.out.println("str1.compareTo(str6): " + str1.compareTo(str6)); 

    str2 = str2.intern();
    str3 = str3.intern();
    str4 = str4.intern();
    str5 = str5.intern();
    str6 = str6.intern();
    System.out.println("After interning");
    System.out.println("str1 == str2: " + (str1 == str2));  
    System.out.println("str1 == str3: " + (str1 == str3));  
    System.out.println("str1 == str4: " + (str1 == str4));  
    System.out.println("str1 == str5: " + (str1 == str5));  
    System.out.println("str1 == str6: " + (str1 == str6));  

  }

}