Does a HashMap collision cause a resize?

前端 未结 4 1983
别那么骄傲
别那么骄傲 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:36

    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.

提交回复
热议问题