Hello.
I'm very confused with
String creation since i saw this:
1- String s1 = "abc";
2- String s2 = "ab";
3- s2 = s2 + "c";
the result is s1 != s2!!! Why?
Let's supose String constant pool is empty...
1- Creates the String object "abc" in de String constant pool an s1 refers to it.
2- Creates the String object "ab" in de String constant pool an s2 refers to it.
3- Creates de "c" String which is lost soon, and creates de "abc". But this String is existing in the String constant pool..., so s2 should refer to it too.(Thats why String constant pool makes a more efficient use of memory).
then why s1 != s2 if both references should refer to the same String object in the String constant pool... , they wasn't created using "new String()"!!!
Im very confused, i thought i was understanding the String constant pool... :-(