Results 1 to 2 of 2
Thread: Same old Question please reply
- 12-17-2007, 09:23 PM #1Member
- Join Date
- Dec 2007
- Rep Power
Same old Question please reply
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();
if(sh == s1h)
When I compiled the above code
if i try to compile with checking the hash code using "==" then it is giving every time
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.
- 12-18-2007, 01:24 AM #2
- By orchid in forum Advanced JavaReplies: 9Last Post: 12-19-2010, 09:49 AM
- By maheshkumarjava in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 03-29-2008, 11:51 AM
- By Deon in forum New To JavaReplies: 3Last Post: 01-27-2008, 04:58 PM
- By javaplus in forum New To JavaReplies: 0Last Post: 12-24-2007, 11:18 AM
- By sonal in forum New To JavaReplies: 1Last Post: 11-29-2007, 10:17 PM