String s1 = new String("abc");//it is created at heap area
String s2 = "abc";//it is created string constant pool
System.out.println(s1==s2);//false
System.out.println(s1.hashCode());same hashCode
System.out.println(s2.hashCode());same hashCode
The last two lines give the same hashCode()
, but the objects are different.while creating s1 object it create in heap area and s2 object is create in string constant pool.but both are gives same hashCode.i.e my doubt?