We can insert duplicate key using org.apache.common.collections.MultiValuesMap except it.
Is there any way to insert duplicate key into Map implemented class?
If yes,how to work that class get() method?
We can insert duplicate key using org.apache.common.collections.MultiValuesMap except it.
Is there any way to insert duplicate key into Map implemented class?
If yes,how to work that class get() method?
Yes, We can insert duplicate key into IdentityHashMap class.
get()
method check below condition:
if (key1==null ? key2==null : key1.equals(key2)).)
if you try to retrieve value using same key reference with which value was inserted, you will get the value. But if you try to get value using difference key reference (even if it is equal), you will get null.
Example:
// Created IdentityHashMap objects
Map ihm = new IdentityHashMap();
// Inserting keys and values in IdentityHashMap Object
ihm.put(new String("key"), "RI Equation");
ihm.put(new String("key"), "Maxxton");
String rikey = new String("identityKey");
String mkey = new String("identityKey");
ihm.put(rikey, "RI Equation");
ihm.put(mkey, "Maxxton");
// Print IdentityHashMap after adding keys
System.out.println("IdentityHashMap after adding key :" + ihm);
System.out.println("Getting value from IdentityHashMap :"+ ihm.get("identityKey"));
System.out.println("Getting value from IdentityHashMap :"+ ihm.get(rikey));
System.out.println("Getting value from IdentityHashMap :"+ ihm.get(mkey));