IdentifyHashMap Class
In Java, IdentityHashMap class implements the Map interface. It also implements the serializable and Cloneable interface. And it extends the AbstractMap class. It requires the objects for the comparison via reference.
Following are the Constructors of the IdentityHashMap class
1. IdentityHashMap().
2. IdentityHashMap(intexpectedMaxSize)
3. IdentityHashMap(Map m)
Below are the methods of AbstractList Class
S.no. |
Method |
Description |
1 |
clear() |
It is used to remove all the mappings from the map. |
2 |
clone() |
It is used to get a copy of the map. |
3 |
containsKey(Object key) |
It is used to get the mapping of a specified key. |
4 |
containsKey(Object value) |
It is used to get the mapping of a specified value. |
5 |
entrySet() |
It is used to set a view for mapping. |
6 |
equals(Object o) |
It is used to compare an object from another object in the map. |
7 |
get(Object key) |
It is used to get the value from the specified position in the map. |
8 |
hashCode() |
It used to get the hash code from the map. |
9 |
hashCode() |
It used to get the hash code from the map. |
9 |
isEmpty() |
It is used to check whether the map contains any key-value or not. |
10 |
keySet() |
It is used to set view in the map. |
11 |
put(K key, V value). |
It is used for adding key and value in the map. |
12 |
putAll(Map m) |
It used for copying the entire map. |
13 |
remove(Object key) |
It is used to remove the key from a weak hash map. |
14 |
size() |
It is used for getting the total number of key-value in the map. |
15 |
values() |
It is used to get the values from the map. |
Example:
import java.util.Map;
import java.util.HashMap;
import java.util.IdentityHashMap;
public class IdentityHashMapDemo1
{
public static void main(String[] args)
{
Map a = new HashMap();
Map b = new IdentityHashMap();
a.put("H_key","H_value");
a.put(new String("H_key"),"H_value1");
b.put("H_key","H_value");
b.put(new String("H_key"),"H_value1");
System.out.println("HashMapSize : "+a.size());
System.out.println("IdentityHashMapSize : "+b.size());
}
}
Immutable Map
In Java, Immutable Map is a type of Map. It is immutable means it can not be modified, it is fixed after the declaration. If an attempt is made to add, delete or update an element then UnsupportedOperationException is thrown. It also does not allow any null elements.
Following are the Advantages of the ImmutableList.
1. It is threaded safe.
2. The memory is well organized.
Below is the class Hierarchy