title: Override equals method to return false while inserting to HashMap
body: <pre><code>import java.util.HashMap;
  import java.util.Map;
  
  public class MapTest {
      public String id;
      public String getId() {
          return id;
      }
      public void setId(String id) {
          this.id = id;
      }
      @Override
      public int hashCode(){
          return 100;
      }
      @Override
      public boolean equals(Object te){
          return false;
      }
      public static void main(String[] args) {
          MapTest obj = new MapTest();
          MapTest obj1 = new MapTest();
          obj.setId("test");
          obj1.setId("test2");
          Map&lt;MapTest,Integer&gt; test = new HashMap&lt;MapTest,Integer&gt;(); 
          test.put(obj, 1000);
          test.put(obj1, 2000);
          test.put(new MapTest(), 4000);
          System.out.println(test.get(obj)); //1000
          System.out.println(test.get(obj1));//2000
          System.out.println(test.get(new MapTest()));//Null
          System.out.println(test.size());//3
      }
  
  }
  </code></pre>
  
  <p>Here the object returns same hashcodes so inorder to avoid overwriting while adding data to HashMap I have a equals method that returns false. Now when I use get I get the proper data example obj1 and obj are giving exact values but my question is when both their hashcodes are same how java distinguishes different objects and return their exact values from hashmap.</p>