class Demo
{
public static void main(String[] args)
{
String s1 = new String("ABC");
String s2 = s1.concat("ABC");
String s3 = s2.intern();
System.out.println(s2 == s3); //true
String s4 = "ABCABC";
System.out.println(s3 == s4); //true
}
}
String s2 = s1.concat("ABC"); would create a new String object "ABCABC" on the heap area. String s3 = s2.intern(); should create a new String object onto the String constant pool.
Since these are two different objects, their references shouldn't be equal. But seems that i'm missing out on something important related to intern().