Java Collection Tutorial - Java IdentityHashMap.put(K key, V value)


IdentityHashMap.put(K key, V value) has the following syntax.

public V put(K key, V value)


In the following code shows how to use IdentityHashMap.put(K key, V value) method.

//  ww w.  j a va2s . co  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, "from");

    Object v1 = objMap.get(o1);
    Object v2 = objMap.get(o2);

        System.out.println( objMap);

The code above generates the following result.