title: Why is equals() not called while adding to HashSet and hashCode matches?
body: <p>When I run this code why only <code>hashCode()</code> is called not <code>equals</code> method while my <code>hashCode()</code> implementation generate same <code>hashCode</code> for both entries to <code>HashSet</code>?</p>
  
  <pre><code>import java.util.HashSet;
  
  public class Test1 {
      public static void main(String[] args) {
          Student st=new Student(89);
          HashSet st1=new HashSet();
          st1.add(st);
          st1.add(st);
          System.out.println("Ho size="+st1.size());
      }
  }
  class Student{
      private int name;
      private int ID;
      public Student(int iD) {
          super();
          this.ID = iD;
      }
      @Override
      public int hashCode() {
          System.out.println("Hello-hashcode");
          return ID;
      }
      @Override
      public boolean equals(Object obj) {
          System.out.println("Hello-equals");
          if(obj instanceof Student){
              if(this.ID==((Student)obj).ID){
                  return true;
              }
              else{
                  return false;
              }
          }
          return false;  
      }
  }
  </code></pre>
  
  <p>The output for this is:</p>
  
  <pre><code>Hello-hashcode
  Hello-hashcode
  Ho size=1
  </code></pre>