Wednesday, 18 November 2015

Difference between IdentityHashMap and HashMap

In Identity Hashmap, JVM uses == operator to identify duplicate keys.
Ex: IdentityHashMap m=new IdentityHashMap();
Integer i1=new Integer(10);
Integer i2=new Integer(10);
m.put(i1, "GetSure");m.put(i2, "Infotech");
SOP(m) --> O/P: 10 - GetSure, 10 - Infotech
In Hashmap, the JVM uses .equals() method to identify duplicate keys.
Ex: HashMap m=new HashMap();
Integer i1=new Integer(10);
Integer i2=new Integer(10);
m.put(i1, "GetSure");
m.put(i2, "Infotech");
SOP(m) --> O/P: Only 10 - Infotech
 

No comments:

Post a Comment