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. | 0 |
By: [email protected] On: Wed Apr 18 15:25:57 IST 2018 0 0 2 | 2 |
Are You Satisfied :0Yes0No |