Alex Rivera | Logout

HashMap initialization parameters (load / initialcapacity)

Asked 2009-01-12T10:05:17.790
43

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

In an ArrayList, the efficient number is N (N already assumes future grow). What should be the parameters for a HashMap? ((int)(N * 0.75d), 0.75d)? More? Less? What is the effect of changing the load factor?

Edit
Report

1 Answer

2

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.

answered 2009-02-25T02:02:08.413

Your Answer