Does a HashMap collision cause a resize?

前端 未结 4 1938
别那么骄傲
别那么骄傲 2021-01-14 15:03

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?

4条回答
  •  被撕碎了的回忆
    2021-01-14 15:28

    Either could happen - it depends on the fill ratio of the HashMap.

    Usually however, it will be added to the list for that bucket - the HashMap class is designed so that resizes are comparatively rare (because they are more expensive).

提交回复
热议问题