title: Understanding the workings of equals and hashCode in a HashMap
body: <p>I have this test code:</p>
  
  <pre><code>import java.util.*;
  
  class MapEQ {
  
    public static void main(String[] args) {
     Map&lt;ToDos, String&gt; m = new HashMap&lt;ToDos, String&gt;();
     ToDos t1 = new ToDos("Monday");
     ToDos t2 = new ToDos("Monday");
     ToDos t3 = new ToDos("Tuesday");
     m.put(t1, "doLaundry");
     m.put(t2, "payBills");
     m.put(t3, "cleanAttic");
     System.out.println(m.size());
  } }
  
  class ToDos{
  
    String day;
  
    ToDos(String d) { day = d; }
  
    public boolean equals(Object o) {
        return ((ToDos)o).day == this.day;
   }
  
  // public int hashCode() { return 9; }
  }
  </code></pre>
  
  <p>When <code>// public int hashCode() { return 9; }</code> is uncommented  <code>m.size()</code> returns 2, when it's left commented it returns three. Why?</p>