Why ArrayList grows at a rate of 1.5, but for Hashmap it's 2?

后端 未结 7 1125
暖寄归人
暖寄归人 2020-12-28 17:28

As per Sun Java Implementation, during expansion, ArrayList grows to 3/2 it\'s initial capacity whereas for HashMap the expansion rate is double. What is reason behind this?

7条回答
  •  囚心锁ツ
    2020-12-28 18:12

    A general rule to avoid collisions on Maps is to keep to load factor max at around 0.75 To decrease possibility of collisions and avoid expensive copying process HashMap grows at a larger rate.

    Also as @Peter says, it must be a power of 2.

提交回复
热议问题