title: Internal structure of Hashmap
body: <p>I was going through the internal structure of <code>HashMap</code> and got stuck in the concept of how a bucket stores multiple objects.</p>
  
  <p>As <code>HashMap</code> is an array of <code>Entry</code> objects, every index of array is a bucket. The <code>Entry</code> class is like</p>
  
  <pre><code>static class Entry&lt;K,V&gt; implements Map.Entry&lt;K,V&gt; {  
      K key;  
      V  value;  
      Entry&lt;K,V&gt; next_entry;  
      int hash;  
  }   
  </code></pre>
  
  <p>On Adding a new key-value pair</p>
  
  <ul>
  <li>If we are adding a value with a key which has already been saved in HashMap, then the value gets overwritten.</li>
  <li>Otherwise the element is added to the bucket. If the bucket already has at least one element, a new one is gets added and placed in the first position in the bucket. Its next field refers to the old element.</li>
  </ul>
  
  <p>So how can a bucket store multiple object as per the 2nd point?</p>