Javatpoint Logo

hashcode

By: nagand*** On: Sun Apr 08 19:15:31 IST 2018     Question Reputation0 Answer Reputation0 Quiz Belt Series Points0  0Blank User
when we have a need to use hashcode() method in collectionsUp0Down

 
Whenever you need fast retrieval of objects you need to use the hashCode() method.
The objects are stored in the heap in Java, and they are stored in the buckets . The hashcodes are like a tag on those buckets, which help JVM in
faster retrieval of objects. By overriding hashCode() method you are basically generating those tags for the buckets, i.e rather than auto-generated
hashcodes(from the Object class' hashCode() method) you are creating your own hashcodes.Now, when you override hashCode() and generate a hash
code(a non-decimal number) then at the time of retrieving that object JVM will first look-up into the bucket whose tag you have provided, rather than
searching over all the buckets, this will save a lot of time for JVM to retrieve objects.
Image Created0Down

By: [email protected] On: Wed Apr 18 15:25:57 IST 2018 Question Reputation0 Answer Reputation0 Belt Series Points2 2User Image
Are You Satisfied :0Yes0No