String s1=new String("abc"); String s2=new String("abc"); (s1==s2)-->result is
-
true
-
false
-
compilation error
-
exception thrown at runtime
When using 'new String()', a new String object is created on the heap each time, even if the character sequence is the same. s1 and s2 are two distinct objects with the same value 'abc'. The '==' operator compares object references, not content, so s1 == s2 returns false.
Using new String("abc") explicitly creates a new String object on the heap rather than reusing the interned string pool entry, so s1 and s2 reference two distinct objects even though their contents are identical. The == operator compares object references (identity), not content, so s1==s2 evaluates to false — you'd need .equals() to compare the actual character content.