CODE
import java.util.*;
class IdentityHashMapDemo
{
IdentityHashMap hm = new IdentityHashMap();
Integer i1 = new Integer(10);
Integer i2 = new Integer(10);
hm.put(i1, "Sachin");
hm.put(i2, "Dravid");
System.out.println(hm);
}
{10=Sachin, 10=Dravid}
IdentityHashMap
with HashMap
in the above program?i1
and i2
are duplicate keys because i1.equals( i2 )
returns true
. As a result, the output would be: