putiing objects to hash based collection
<p>Suppose I have the below class.</p>

<pre><code>class S{

String txt = null;

S(String i){
txt=i;
}

public static void main(String args []){
S s1 = new S("a");
S s2 = new S("b");
S s3 = new S("a"); 

Map m = new HashMap ();
m.put(s1, "v11");
m.put(s2, "v22");
m.put(s3, "v33");

System.out.println(m.size());   
}

//just a plain implementation
 public boolean equals(Object o)
 {
      S cc = (S) o;
      if (this.i.equals(cc.i))
      {    
         return true;
      }
      else
      {
         return false;
      }    
   }

   public int hashCode()
   {
      return 222;
   }  

}
</code></pre>

<p>This will return size as 2 when running above. Its totally fine. If we comment the hashCode() it return 3 which is also correct. But if we comment the equals and keep the hashCode it should return 2 right? instead it returns 3. When putting objects to hashmap map will check the hash code of an object and if its same it will replace the previous value of the map to the new one right?</p>

<p>Thank You.</p>
