// StringCompare.java   P. Conrad for CISC370, 06/07/2007
// Show some oddities with string comparison in Java
// Mostly, why you should always use .equals() instead of ==
// when comparing String objects

class StringCompare {
    
    public static void main(String args[])  {


	// two different ways to allocate a string
	// both are allocated on the heap, while the
	// actual variable containing the reference is allocated
	// on the stack.
	// But, they refer to different objects

	String team="Eagles";
	String band="Eagles";
	String birds= new String("Eagles");
	
	System.out.println("team = " + team);
	System.out.println("band = " + band);
	System.out.println("birds = " + birds);

	// shallow compare

	if (team == band)
	    System.out.println("team == band");
	else
	    System.out.println("team != band");
		
	if (team == birds)
	    System.out.println("team == birds");
	else
	    System.out.println("team != birds");
		
	// deep compare

	if (team.equals(birds))
	    System.out.println("team.equals(birds)");
	else
	    System.out.println("!team.equals(birds)");
		
    } // main
    
}
