The concept is the same. The hashCode is used to identify in which bucket the object will be place in.
Joined: Feb 06, 2011
in HashSet, we can pass the searching object to the constructor of Hashset.
so the construtor is calling hashcode() method of searching object and going to the specific bucket for applying equals() method on those specific limited objects. this is clear to me...
but in HashMap.. we should pass key to get value... how this process is going? i m in confusion, will you please clear it?
veda kakarla wrote:......but in HashMap.. we should pass key to get value... how this process is going? i m in confusion, will you please clear it?
In a HashMap, essentially all the keys are stored in a Set. So, the same concept as for Set applies here too. When you ask for a value by giving the key, hashCode() and equals() shall be used to identify the bucket in which the key is in. Once the key is located, the value can be retrieved in no time.