Java Collection Tutorial - Java IdentityHashMap(int expectedMaxSize) Constructor


IdentityHashMap(int expectedMaxSize) constructor from IdentityHashMap has the following syntax.

public IdentityHashMap(int expectedMaxSize)


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

import java.util.IdentityHashMap;
import java.util.Map;
//  w ww  .  j a va 2s .co  m
public class Main {
  public static void main(String[] argv) throws Exception {
    Map<Object, Object> objMap = new IdentityHashMap<Object, Object>(5);

    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