Integer i = new Integer(10);
Integer j =10;
System.out.println(i==j); // false
String a1 = new String("abc");
String a2 = "abc";
System.out.println(a1==a2); // false
But to make Java more memory efficient, the JVM sets aside a special area of memory called the "String constant pool." When the compiler encounters a String literal, it checks the pool to see if an identical String already exists. If a match is found, the reference to the new literal is directed to the existing String, and no new String literal object is created. (The existing String simply has an additional reference.) So String literals are immutable. So, both a1 and a2 will have two reference pointing to same memory location then why "==" doesn't return true?