• Post Reply Bookmark Topic Watch Topic
  • New Topic

What is use of hashcode?  RSS feed

 
Hrishikesh Ghatnekar
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can somebody tell me what is use of hascode? Till this day I was thinking that hascode is used to identify uniqueness of the object , but actually it is not.

If I create two string objects

String a = �haha�;
String b = new String(�haha�):

It creates two different objects but the hascode is same for two different objects.
Now in light of this , What is the use of hashcode?

Thanks
Hrishikesh
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a very good answer to your general question in the JavaDocs for the base method: Object.hashCode(). Please make a best-effort attempt to answer your question (or ask really specific questions), especially in the intermediate forum.

If you're unfamiliar with the JavaDocs, it is imperative that you learn to use them if you want to progress in Java. Ask if you need help finding or navigating them. If not, read the description for hashCode() and post again if you still have questions.

You might also want to look at String.hashCode() to see why it gives the results you see, which are quite different from Object.hashCode().
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!