If you take the following code :
class TestClass {
public static void main(
String[] args ) {
String s1 = new String( "Welcome to Java" );
String s2 = s1;
s1 += " and Welcome to HTML";
if( s1 == s2 ) {
System.out.println( "s1 is equal to s2" );
}
else {
System.out.println( "s1 is NOT equal to s2" );
}
}
}
and run it, the program will print :
s1 is NOT equal to s2
My question is, since s1 and s2 are both references to String objects, and pointing to the same String object, why are they not still equal after the string is appended ?
Rod