public class A {
static String s1 = "I am A";
public static void main(String[] args) {
String s2 = "I am A";
System.out.println(s1 == s2);
}
}
Above program outputs “true”. Both are two different identifiers/objects how the output is “true” ?
My understanding is that the JVM will create different reference for each object, if so how the output is true?
Java manages a
Stringliteral pool. It reuses these literals when it can. Therefore the two objects are actually the sameStringobject and==returns true.I believe this is called string interning