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
This is my guess:
String s1 = "a" + "bc"; String s2 = "ab" + "c";
I think that are compile time these are determined to produce the same string and so only one object is made for both.
But when you add "d" to both of them, this is done separately for both strings (since it's done during real time, there could be things like exceptions interrupting it etc, so it can't pre-do it) and so it doesn't automatically make them reference one object.