Java IdentityHashMap() Constructor

Syntax

IdentityHashMap() constructor from IdentityHashMap has the following syntax.

public IdentityHashMap()

Example

In the following code shows how to use IdentityHashMap.IdentityHashMap() constructor.


//ww  w .  ja va  2s .c o m
import java.util.IdentityHashMap;
import java.util.Map;

public class Main {
  public static void main(String[] argv) throws Exception {
    Map<Object, Object> objMap = new IdentityHashMap<Object, Object>();

    Object o1 = new Integer(123);
    Object o2 = new Integer(123);
    objMap.put(o1, "first");
    objMap.put(o2, "second");

    Object v1 = objMap.get(o1); // first
    Object v2 = objMap.get(o2); // second
  }
}