aspose file tools*
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
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: The purpose of hashCode()