This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes The purpose of hashCode() Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "The purpose of hashCode()" Watch "The purpose of hashCode()" New topic
Author

The purpose of hashCode()

Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
Will it be o.k. to return the unique key on the object as it's hashCode. For example, SSN for Person class and VIN for Vehicle class.
As purpose of hashCode is to evenly distribute objects in collection, this will put one object in each bucket...
Thanks
Barkat
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
hashCode has to return an int. Returning a unique int for each unique object is generally best.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: The purpose of hashCode()
 
Similar Threads
doubt regarding hashcode
Khalid Mock - Hashcode Q
hashCode()
null key in a HashMap
Practice Question