問題描述
如果在放入 HashMap 期間發(fā)生沖突,是調(diào)整映射大小還是將條目添加到特定存儲桶中的列表中?
When there is a collision during a put in a HashMap is the map resized or is the entry added to a list in that particular bucket?
推薦答案
當(dāng)你說'碰撞'時,你的意思是相同的哈希碼嗎?hashcode 用于確定要使用 HashMap 中的哪個桶,桶由具有相同 hashcode 的所有條目的鏈表組成.然后在返回或引導(dǎo) (get/put) 之前比較條目是否相等(使用 .equals()).
When you say 'collision', do you mean the same hashcode? The hashcode is used to determine what bucket in a HashMap is to be used, and the bucket is made up of a linked list of all the entries with the same hashcode. The entries are then compared for equality (using .equals()) before being returned or booted (get/put).
請注意,這是專門的 HashMap(因為這是您詢問的那個),以及其他實現(xiàn),YMMV.
Note that this is the HashMap specifically (since that's the one you asked about), and with other implementations, YMMV.
這篇關(guān)于HashMap 沖突是否會導(dǎo)致調(diào)整大小?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!