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?
Regarding the load factor, I’ll simply quote from the HashMap javadoc:
Meaning, the load factor should not be changed from
.75, unless you have some specific optimization you are going to do. Initial capacity is the only thing you want to change, and set it according to yourNvalue – meaning(N / 0.75) + 1, or something in that area. This will ensure that the table will always be large enough and no rehashing will occur.