title: Detail the big-O of Hashmap - put() method by real code in Java 8
body: <p>I 'm novice in Algorithm. I read and aware that big-O of put(K key, V value) in Hashmap is O(1).
  When I went to core of HashMap class</p>
  
  <pre><code>    final V putVal(int hash, K key, V value, boolean onlyIfAbsent,
                 boolean evict) {
      Node&lt;K,V&gt;[] tab; Node&lt;K,V&gt; p; int n, i;
      if ((tab = table) == null || (n = tab.length) == 0)
          //...
      if ((p = tab[i = (n - 1) &amp; hash]) == null)
          //...
      else {
          Node&lt;K,V&gt; e; K k;
          if (p.hash == hash &amp;&amp;
              ((k = p.key) == key || (key != null &amp;&amp; key.equals(k))))
              e = p;
          else if (p instanceof TreeNode)
              // ...
          else {
              for (int binCount = 0; ; ++binCount) {
                  if ((e = p.next) == null) {
                      p.next = newNode(hash, key, value, null);
                      // ...
                  }
                  if (e.hash == hash &amp;&amp;
                      ((k = e.key) == key || (key != null &amp;&amp; key.equals(k))))
                      break;
                  p = e;
              }
          }
          if (e != null) { // existing mapping for key
             // ...
          }
      }
      ...
      return null;
  }
  </code></pre>
  
  <p>As you can see, when adding <strong>new</strong> item to hashmap, it will iterate max n (all item in hashmap) with "For Loop" above:</p>
  
  <pre><code> for (int binCount = 0; ; ++binCount) {
  </code></pre>
  
  <p>Now, big-O of For Loop here is O(n) --> Why big-O of put(K key, V value) in HashMap can be O(1) ?
  Where do I understand wrongly ?</p>
  
  <p>Thanks very much.</p>