Associating a Value with an Object : IdentityHashMap « Collections Data Structure « Java






Associating a Value with an Object

import java.util.IdentityHashMap;
import java.util.Map;

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

    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
  }
}

 








Related examples in the same category