String b = a.substring(1); returns an instance of a string that contains "bc" , but this instance is not part of the string pool (only literals are interned by default, a string created with new String(data) and returned from methods such as substring or nextLine not interned by default) .
Now when you call
b.intern();
this method checks if the String string contains a string equal to the one stored in b (which is "bc"), and if not, it puts that string there. So sine there is no line representing "bc" in the pool, the line from b will be placed there.
So now the row pool contains "abc" and "bc" .
Because of this, when you call
String c = "bc";
the string literal representing bc (the same as in link b ) will be reused from the pool, which means that b and c will contain the same instance.
This confirms the result of b==c , which returns true .
source share