Java IdentityHashMap - size() Method
The java.util.IdentityHashMap.size() method returns the total number of key-value mapping present in this map.
Syntax
public int size()
Parameters
No parameter is required.
Return Value
Returns the total number of key-value mapping in this map.
Exception
NA
Example:
In the example below, the java.util.IdentityHashMap.size() method is used to find out the total number of key-value mapping in the given identity hash map.
import java.util.*; public class MyClass { public static void main(String[] args) { //creating a identity hash map IdentityHashMap<Integer, String> MyMap = new IdentityHashMap<Integer, String>(); //populating the map MyMap.put(101, "John"); MyMap.put(102, "Marry"); MyMap.put(103, "Kim"); MyMap.put(104, "Jo"); System.out.println("Size of MyMap: "+ MyMap.size()); //adding one more pair in the map MyMap.put(105, "Ramesh"); System.out.println("Size of MyMap: "+ MyMap.size()); } }
The output of the above code will be:
Size of MyMap: 4 Size of MyMap: 5
❮ Java.util - IdentityHashMap