Hi All,
Please don't get weird with the same old question. I am getting confusion in the string comparision.
I am trying to execute the following programme where i am getting doubt.
String s = new String("abcus");
String s1 = new String("abcus");
String s2 = new String("abcus");
String s3 = new String("abcus");
int sh = s.hashCode();
int s1h = s1.hashCode();
int s2h = s2.hashCode();
int s3h = s3.hashCode();
System.out.println(sh);
System.out.println(s1h);
System.out.println(s2h);
System.out.println(s3h);
if(sh == s1h)
{
System.out.println("equal");
}
else{
System.out.println("not equal");
}
}
When I compiled the above code
92599936
92599936
92599936
92599936
if i try to compile with checking the hash code using "==" then it is giving every time
as EQUAL.
if i try to compile with checking the reference variable using "==" then it is giving as NOT EQUAL.
By the above output i understand that while checking with "==" it not only checks the HashCode it also compares other thing.
I tried to get the actual implementation of Equals method and "==" but not able to find
Could you please let me know the reason behind the above checking and it would be great if I get the url for actual implementation of the above code.
Thanks in advance to all.
Regards,
Venkat