Possible Duplicate:
Questions about Java's String pool
String s1 = "length";
String s2 = "length";
System.out.println("EQUAL: " + (s1 == s2));
String s3 = "length: 10";
String s4 = "length: " + s3.length();
System.out.println(s3.length());
System.out.println(s4.length());
System.out.println("EQUAL: " + (s3 == s4));
Output :
EQUAL: true //Understood same string reference in string pool
10
10
EQUAL: false // Why?
Creates new String object.
So, s3 reference to different object and s4 references to different object, which makes
==condition returnfalse.