Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-17-2007, 10:23 PM
Member
 
Join Date: Dec 2007
Posts: 1
venat123 is on a distinguished road
Same old Question please reply
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-18-2007, 02:24 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
When Are Two Strings Equal?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question mark colon operator question orchid Advanced Java 8 11-27-2008 08:36 AM
JSP Question maheshkumarjava JavaServer Pages (JSP) and JSTL 1 03-29-2008 12:51 PM
Need help on this question Deon New To Java 3 01-27-2008 05:58 PM
JNI question javaplus New To Java 0 12-24-2007 12:18 PM
Need help with a question please sonal New To Java 1 11-29-2007 11:17 PM


All times are GMT +3. The time now is 04:27 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org