FileDocCategorySizeDatePackage
Equality.javaAPI DocExample829Tue Dec 25 20:04:10 GMT 2001None

Equality

public class Equality extends Object

Fields Summary
Constructors Summary
Methods Summary
public voidcompare(java.lang.String s1, java.lang.String s2)


		System.out.print("==:       ");
		System.out.println(s1 == s2);
		System.out.println(".equals():" + s1.equals(s2));
		System.out.println(); 
	
public static voidmain(java.lang.String[] args)

 
		new Equality().run();
	
public voidrun()

		String x = "hello";

		String y = Equality2.getString();
	
		// Assuming Equality2 uses a String constant, this prints true,true
		compare(x, y);

		// A "new String" is uniquely created, so this prints false, true
		compare(x, new String(y));

		// The substring operator creates a new String, prints false, true
		compare(x, "hello world".substring(0, 5));

		// The intern() operator returns a string from the pool of unique
		// strings, so this should print true, true.
		compare(x, new String(x).intern());