This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
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
 
 
subject: The purpose of hashCode()
 
Similar Threads
Practice Question
doubt regarding hashcode
Khalid Mock - Hashcode Q
null key in a HashMap
hashCode()