import java.util.IdentityHashMap;
import java.util.Map;
public class AssociatingAValue {
public static void main(String[] args) {
// TODO Auto-generated method stub
Map objMap = new IdentityHashMap();
// Add the object and value pair to the map
Object o1 = new Integer(123);
Object o2 = new Integer(123);
objMap.put(o1, "first");
objMap.put(o2, "second");
// Retrieve the value associated with the objects
Object v1 = objMap.get(o1); // first
Object v2 = objMap.get(o2); // second
System.out.println(objMap);
}
}
Console:
{123=first, 123=second}