This code is from John Meyer's Mock and little bit edit by me,
import java.util.*;
class test{
public static void main(
String args[] )
{
Map m = new HashMap();
String str = null;
m.put(new
test() , "mill" );
m.put(new test() , "sill" );
m.put(new test() , "sill" );
m.put(null, "sill" );
String key = "key";
m.put(key, "value");
m.put(null, "sill" );
m.put(null, "sill" );
System.out.println(m.size());
System.out.println(m.get(null));
System.out.println(m.get(key));
Integer in = 5;
m.put(in,25);
m.put(12,26);
System.out.println(m.get(12));
System.out.println(m.get(in));
}
/*public boolean equals( Object o)
{
return true; // 1
}
public int hashCode()
{
return 0;
}*/
}
output is
5 (m.size())
sill (m.get(null))
value(m.get(key))
26 (m.get(12))
25 (m.get(in))
can anyone explain me , why is size 5? What is with key with int & Integer. If i comment both m.put(12,26) and m.put(in,25), size is still 5.
What are the behaviour of equals and hashCode methods. although both methods are commented, i can find my object through key?
thanks