, even
though they have the same content. The == operator compares the references of two objects, not
their content.
s1.intern() == s2.intern(): This returns true because both s1.intern() and s2.intern() return a reference
to the same string object in the string pool, which has the content “Hello Java 17”. The intern()
method ensures that there is only one copy of each distinct string value in the string pool.
“Hello Java 17” == s2: This returns false because “Hello Java 17” is a string literal, which is
automatically interned and stored in the string pool, while s2 is a string object created with the new
operator, which is not interned by default and stored in the heap. Therefore, they have different
references and are not equal using the == operator.
Reference: String (Java SE 17 & JDK 17) - Oracle