在Java中的HashMap中重新哈希 [英] Rehashing in HashMap in Java
问题描述
我对HashMap
中的重新哈希处理的概念存有疑问.
I have a small doubt with the concept of Rehashing in HashMap
.
让我们说我有一个大小为8的HashMap
,并且其中有一个在索引7处存在的Object(E1).因此,当我们放置多个元素时,迫使HashMap增大其内部Array的大小,这将导致重新哈希.
Lets say I have a HashMap
with size 8 and within that I have an Object(E1) present at index 7. So when we put multiple elements, forcing the HashMap to increase its internal Array size, which will lead to rehashing.
所以我的问题是,经过重新哈希处理后,我的Object(E1)会被放置在第7个索引处还是会得到另一个存储桶?
So my question goes, After the rehashing, will my Object(E1) be placed at 7th index or will it get a different bucket.
赞赏有用的回复和参考.
Appreciate useful response and references.
推荐答案
放置密钥的存储桶是其hashCode
模数的函数,该模数是用于保存HashMap的数组的大小(存储桶数) ),因此重新哈希可以将密钥移到其他存储桶.
The bucket your key is placed in is a function of its hashCode
modulus the size of the array used to hold the HashMap (which is the number of buckets), so re-hashing can move a key to a different bucket.
这篇关于在Java中的HashMap中重新哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!