title: HashMap Java 8 implementation
body: <p>As per the following link document: <a href="https://dzone.com/articles/hashmap-performance" rel="noreferrer">Java HashMap Implementation</a></p>
  
  <p>I'm confused with the implementation of <code>HashMap</code> (or rather, an enhancement in <code>HashMap</code>). My queries are:</p>
  
  <p><strong>Firstly</strong></p>
  
  <pre><code>static final int TREEIFY_THRESHOLD = 8;
  static final int UNTREEIFY_THRESHOLD = 6;
  static final int MIN_TREEIFY_CAPACITY = 64;
  </code></pre>
  
  <p>Why and how are these constants used? <strong>I want some clear examples for this.</strong>
  How they are achieving a performance gain with this?</p>
  
  <p><strong>Secondly</strong></p>
  
  <p>If you see the source code of <code>HashMap</code> in JDK, you will find the following static inner class:</p>
  
  <pre><code>static final class TreeNode&lt;K, V&gt; extends java.util.LinkedHashMap.Entry&lt;K, V&gt; {
      HashMap.TreeNode&lt;K, V&gt; parent;
      HashMap.TreeNode&lt;K, V&gt; left;
      HashMap.TreeNode&lt;K, V&gt; right;
      HashMap.TreeNode&lt;K, V&gt; prev;
      boolean red;
  
      TreeNode(int arg0, K arg1, V arg2, HashMap.Node&lt;K, V&gt; arg3) {
          super(arg0, arg1, arg2, arg3);
      }
  
      final HashMap.TreeNode&lt;K, V&gt; root() {
          HashMap.TreeNode arg0 = this;
  
          while (true) {
              HashMap.TreeNode arg1 = arg0.parent;
              if (arg0.parent == null) {
                  return arg0;
              }
  
              arg0 = arg1;
          }
      }
      //...
  }
  </code></pre>
  
  <p>How is it used? <strong>I just want an explanation of the algorithm</strong>. </p>