title: Limiting the max size of a HashMap in Java
body: <p>I want to limit the maximum size of a <code>HashMap</code> to take metrics on a variety of hashing algorithms that I'm implementing. I looked at the loadfactor in one of <code>HashMap</code>'s overloaded constructors.</p>
  
  <pre><code>HashMap(int initialCapacity, float loadFactor) 
  </code></pre>
  
  <p>I tried setting the loadFactor to 0.0f in the constructor (meaning that I don't want the HashMap to grow in size EVER) but <code>javac</code> calls this invalid: </p>
  
  <pre><code>Exception in thread "main" java.lang.IllegalArgumentException: Illegal load factor: 0.0
          at java.util.HashMap.&lt;init&gt;(HashMap.java:177)
          at hashtables.CustomHash.&lt;init&gt;(Main.java:20)
          at hashtables.Main.main(Main.java:70) Java Result: 1
  </code></pre>
  
  <p>Is there another way to limit the size of <code>HashMap</code> so it doesn't grow ever?</p>