I read this Questions about Java's String pool and understand the basic concept of string pool but still don't understand the behavior.
First: it works if you directly assign the value and both s1 and s2 refer to the same object in the pool
String s1 = "a" + "bc";
String s2 = "ab" + "c";
System.out.println("s1 == s2? " + (s1 == s2));
But then if I change the string s1+="d", then the pool should have a string object "abcd"? then when I change the s2+="d", it should find the string object "abcd" in the pool and should assign the object to s2? but it doesn't and they aren't referred to the same object. WHY is that?
String s1 = "abc";
String s2 = "abc";
System.out.println("s1 == s2? " + (s1 == s2));
s1 += "d";
s2 += "d";
System.out.println("s1 == s2? " + (s1 == s2));