![]() |
VOOZH | about |
The isEmpty() method in Java HashMap class is used to check whether the map contains any key-value mappings.
Example 1: Checking isEmpty() after adding entries to the map
The Mappings are: {Java=1, Language=3, Programming=2}
Is the map empty? false
public boolean isEmpty()
Return Type:
Example 2: Check isEmpty() Before and After Adding Entries
HashMap contents: {}
Is the map empty? true
Updated HashMap contents: {1=Java, 2=Programming, 3=Language}
Is the map empty? false
Example 3: Check isEmpty() on an Empty HashMap
The Mappings are: {}
Is the map empty? true