• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need Help in hashcodes

 
Sekhar Choudary
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone explain the hashCode and equals contract
How to choose hashcode values.
How the integer literals will be identified in java.


Thanks.
 
Henry Wong
author
Marshal
Pie
Posts: 21518
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a nutshell, hashing is a very quick mechanism to distribute objects. It is important because when you have many object that needs to be added, removed, searched, in a collection -- hashing gives a way of doing it without constantly comparing it with other objects in the collection.

The purpose of the hashcode is to find a location -- a bucket to place object. Objects that are in different buckets, are by definition, different objects. However, objects that are in the same bucket, doesn't mean they are equal. These must be further checked with the equals() method.

Henry
 
amit k prabhat
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi shekar,

For further clarification check the following thread
how many string objects will be created
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic