public class Example{
public static void main(String args[]){
String s1=new String("name");
String s2="name";
System.out.println(s1==s2);
}}
Why does the above code return false
? When a new string "name" is created it's created in the string constant pool as well as the heap. Next when the other string is created using the literal "name", should it not refer to the same object created int heap, as the literal "name" already exist in String Constant Pool?