HashMap initialization parameters (load / initialcapacity)

前端 未结 9 1481
[愿得一人]
[愿得一人] 2020-12-04 10:54

What values should I pass to create an efficient HashMap / HashMap based structures for N items?

In an ArrayList, the efficien

9条回答
  •  粉色の甜心
    2020-12-04 11:12

    Referring to HashMap source code will help.

    If the number of entries reaches threshold(capacity * load factor), rehashing is done automatically. That means too small load factor can incur frequent rehashing as entries grow.

提交回复
热议问题