Menu
Topics Index
...
`

IdentityHashMapDemo - Java Example Program


IdentityHashMapDemo
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);
}
OUTPUT

{10=Sachin, 10=Dravid}

DESCRIPTION

THINGS TO TRY
  • What happens if we replace IdentityHashMap with HashMap in the above program?
    In that case, i1 and i2 are duplicate keys because i1.equals( i2 ) returns true. As a result, the output would be:
    {10=Dravid}

© meritcampus 2019

All Rights Reserved.

Open In App