![]() |
VOOZH | about |
The size() method of the Java HashMap class is used to retrieve the number of key-value pairs currently stored in the HashMap.
Example 1: This example demonstrates the use of the size() method to get the number of elements in the HashMap.
Size of the HashMap: 3
public int size()
Return Type: It returns an int value representing the number of key-value mapping in the HashMap.
Example 2: This example demonstrates the size of the HashMap after removing an element.
Size of the HashMap: 4 Size of the HashMap After removal: 3