Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Is hashCode() return the actual address ?

807603Dec 17 2007 — edited Dec 18 2007
String str1 = new String("abc");
String str2 = new String("abc");

System.out.println(str1==str2); // it will print 'false' as references of str1 and str2 are different
System.out.println(str1.hashCode()==str2.hashCode()); // it will print 'true'

If hashCode( ) return integer value of the address(or reference) of an object then how str1 and str2 are same ? As I know 'new' always return a new memory reference for an object. So what hashCode() return ?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 15 2008
Added on Dec 17 2007
6 comments
797 views