String s1 = "A"+"B";
String s2 = "AB";
System.out.println(s1 == s2); // true
String s1 and s2 should refer to String value "AB" in String constant pool. So one value "AB" one reference, reference comparison giving is true. (this is acceptable according to the theory I am aware of)
String st1 = "C D";
st1 += " E";
String str2 = "C D E";
System.out.println(st1 == str2); // false
String str1 and str2 both should refer to String "C D E" in String constant pool (two identical values cannot be in String pool ). Then why the reference comparison of str1 and str2 return false?
What I am missing here?
Thanks