public static void main (String[] args) {
String s1 = new String("hello");
String s2 = new String("hello");
s1.intern();
s2.intern();
System.out.println(s1 == s2); // why this returns false ?
}
as per my understanding, 1st call to intern method should have created a 'string intern pool' with a single string "hello". second call to intern method would have done nothing (as "hello" string is already present in pool). Now, when i say s1 == s2 i am expecting JVM to compare "hello" string from string intern pool and return true.