What values should I pass to create an efficient HashMap / HashMap based structures for N items?
In an ArrayList, the efficien
It's also notable that having a HashMap on the small side makes hash collisions more likely, which can slow down lookup. Hence, if you really worry about the speed of the map, and less about its size, it might be worth making it a bit too large for the data it needs to hold. Since memory is cheap, I typically initialise HashMaps for a known number of items with
HashMap myMap = new HashMap(numberOfElements * 2);
Feel free to disagree, in fact I'd quite like to have this idea verified or thrown out.