hello people,
I am checking the string pool and its basic operation i.e. how it works
public class Test
{
public static void main(String[] args)
{
String s1 = new String("abc");
String s2 = "abc";
String s3 = s2;
System.out.println("Hash Table: ");
System.out.println(s1.hashCode()+ " "+ s2.hashCode()+" "+s3.hashCode());
System.out.println("== Check: ");
System.out.println((s1==s2) + " " + (s2==s3) + " " + (s1==s3));
System.out.println("equals Check: ");
System.out.println(s1.equals(s2)+" "+s2.equals(s3)+" "+s1.equals(s3));
}
}
I can't understand why s1,s2,s3 are having same hashcode although i created as strings and objects as shown. all equality and == working is fine. except that hashcode. if they are all having same hashcode how the == operator checks if they are all referring to same location