Best HashMap initial capacity while indexing a List

前端 未结 6 682
小蘑菇
小蘑菇 2021-01-31 16:46

I have a list (List list) and I want to index its objects by their ids using a map (HashMap map). I always use list.si

6条回答
  •  感动是毒
    2021-01-31 17:19

    The rule of thumb if you don't know load factor/capacity internals :

    initialCapacityToUse = (Expected No. of elements in map / 0.75) + 1
    

    With this initial capacity value, the rehash will not occur for storing given expected no. of elements in map.

提交回复
热议问题