Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change the hashmap load factor

We know that hashmap has default load factor 0.75, and if I want to change it how to do that.

Is there any method so that we can set and use the load factory. I have 100k records and I don't want to rehashing again and again, I want to change the load factor so that it can work efficiently without rehashing.

like image 430
shiv Avatar asked Sep 15 '25 11:09

shiv


1 Answers

you can not change that after the map is created, the most you can y use the constructor defined for that

as the doc states:

public HashMap(int initialCapacity, float loadFactor)

Constructs an empty HashMap with the specified initial capacity and load factor.

 Map<String, String> x = new HashMap<>(10, 0.85f);
like image 133
ΦXocę 웃 Пepeúpa ツ Avatar answered Sep 18 '25 10:09

ΦXocę 웃 Пepeúpa ツ