HashMap碰撞是否会导致调整大小? [英] Does a HashMap collision cause a resize?

查看:188
本文介绍了HashMap碰撞是否会导致调整大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在HashMap中放置过程中发生冲突时,是否调整了地图大小或将该条目添加到特定存储桶中的列表中?

解决方案

当你说'碰撞'时,你的意思是相同的哈希码?哈希码用于确定要使用HashMap中的哪个存储区,并且该存储区由所有具有相同哈希码的条目的链接列表组成。然后在返回或启动(get / put)之前比较它们的相等性(使用.equals())。注意,这是HashMap的具体实现(因为这是你问的那个),以及其他实现,YMMV。


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?

解决方案

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).

Note that this is the HashMap specifically (since that's the one you asked about), and with other implementations, YMMV.

这篇关于HashMap碰撞是否会导致调整大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆