Javadoc says that if in the string pool there is an equal String that the intern() method will return the String.
public class Demo {
public static void main(String[] args) {
String str1 = "Apple";
String str2 = new String("Apple");
System.out.println(str1.intern() == str2); //false
System.out.println(str1 == str2.intern()); //true
}
}
I expected to get true in both cases.