title: Java HashMap resizing
body: <p>Let's assume we have some code</p>
  
  <pre><code>class WrongHashCode{
      public int code=0;
  
      @Override
      public int hashCode(){
          return code;
      }
  }
  public class Rehashing {
      public static void main(String[] args) {
  
          //Initial capacity is 2 and load factor 75%
          HashMap&lt;WrongHashCode,String&gt; hashMap=new HashMap&lt;&gt;(2,0.75f);
  
          WrongHashCode wrongHashCode=new WrongHashCode();
          //put object to be lost
          hashMap.put(wrongHashCode,"Test1");
  
          //Change hashcode of same Key object
          wrongHashCode.code++;
  
          //Resizing hashMap involved 'cause load factor barrier
          hashMap.put(wrongHashCode,"Test2");
  
          //Always 2
          System.out.println("Keys count " + hashMap.keySet().size());
      }
  }
  </code></pre>
  
  <p>So, my question is why after resizing hashMap (that, as far, as I understand involves <strong>rehashing keys</strong>), we still have 2 keys in keySet instead of 1 (since key object is same for both existing KV pairs) ?</p>