Basic Java question: String equality
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? Neil Foley Java manages a String literal pool. It reuses these literals when it can. Therefore the two objects are actually the same String object and == returns true. I believe this is called string interning == checks that the variables are