当前位置:网站首页>Hashcode and equals

Hashcode and equals

2022-07-06 03:48:00 monkeySix

An object as HashMap Medium key When , First calculate the hashcode value , adopt hashcode Value can determine that this object is in HashMap On which slot in the array ,HashMap Each slot in the underlying array stores a linked list , Then compare the of each entity in the linked list key Whether it is equal or not ( use equals Compare ), If equal , Just use the current put Of value, Replace value. otherwise , Add a new one Entry node , The node placed in this slot is at the front .

hashcode The value can be determined in hashmap Which slot in ,equals It can be determined whether there are the same key, Taken together, we can determine this map Is there the same key.

原网站

版权声明
本文为[monkeySix]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202132308145225.html