*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Need Help in hashcodes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Need Help in hashcodes" Watch "Need Help in hashcodes" New topic
Author

Need Help in hashcodes

Sekhar Choudary
Ranch Hand

Joined: May 03, 2008
Posts: 57
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
Sheriff

Joined: Sep 28, 2004
Posts: 18531
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
amit k prabhat
Greenhorn

Joined: Aug 09, 2008
Posts: 6
hi shekar,

For further clarification check the following thread
how many string objects will be created
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need Help in hashcodes
 
Similar Threads
HashSet
Overriding hashCode()
how hashCode() is used in HashMap?
hashcode() in java
need help with the space-time continium