Collision resolution in Java HashMap

前端 未结 9 1988
半阙折子戏
半阙折子戏 2020-12-12 12:29

Java HashMap uses put method to insert the K/V pair in HashMap. Lets say I have used put method and now HashMap<

9条回答
  •  情深已故
    2020-12-12 13:18

    When multiple keys end up in same hash code which is present in same bucket. When the same key has different values then the old value will be replaced with new value.

    Liked list converted to balanced Binary tree from java 8 version on wards in worst case scenario.

    Collision happen when 2 distinct keys generate the same hashcode() value. When there are more collisions then there it will leads to worst performance of hashmap.

    Objects which are are equal according to the equals method must return the same hashCode value. When both objects return the same has code then they will be moved into the same bucket.

提交回复
热议问题