Java HashMap isEmpty() Method Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 Java // Mapping integer value to string keys import java.util.HashMap; public class Geeks { public static void main(String[] args) { // Creating an empty HashMap HashMap<String, Integer> hm = new HashMap<String, Integer>(); // Mapping int values to string keys hm.put("Java", 1); hm.put("Programming", 2); hm.put("Language", 3); // Displaying the HashMap System.out.println("The Mappings are: " + hm); // Checking for the emptiness of Map System.out.println("Is the map empty? " + hm.isEmpty()); } } OutputThe Mappings are: {Java=1, Language=3, Programming=2} Is the map empty? false Syntax of isEmpty() Methodpublic boolean isEmpty()Return Type: It returns true, if the map contains no key-value mapping. It returns false, if the map has one or more key-value mapping.Example 2: Check isEmpty() Before and After Adding Entries Java // Mapping String value to integer keys import java.util.HashMap; public class Geeks { public static void main(String[] args) { // Create an empty HashMap HashMap<Integer, String> map = new HashMap<>(); // Display the HashMap System.out.println("HashMap contents: " + map); // Check if the map is empty System.out.println("Is the map empty? " + map.isEmpty()); // Add key-value pairs map.put(1, "Java"); map.put(2, "Programming"); map.put(3, "Language"); // Display the updated HashMap System.out.println("Updated HashMap contents: " + map); // Check if the map is empty again System.out.println("Is the map empty? " + map.isEmpty()); } } OutputHashMap 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 Java // Java program to demonstrate the working of isEmpty() import java.util.HashMap; class Geeks { public static void main(String[] args) { // Creating an empty HashMap HashMap<String, Integer> hm = new HashMap<>(); // Displaying the HashMap System.out.println("The Mappings are: " + hm); // Checking for the emptiness of Map System.out.println("Is the map empty? " + hm.isEmpty()); } } OutputThe Mappings are: {} Is the map empty? true Comment More infoAdvertise with us Next Article Hashtable isEmpty() Method in Java C chinmoy lenka Follow Improve Article Tags : Misc Java Java-Collections Java - util package Java-Functions Java-HashMap +2 More Practice Tags : JavaJava-CollectionsMisc Similar Reads Java HashSet isEmpty() Method The HashSet isEmpty() in Java is used to check if the HashSet is empty or not.Syntax of HashSet isEmpty() Methodboolean isEmpty()Return Type: This method returns "true" if the HashSet is empty, otherwise returns "false".Example: This example demonstrates how the isEmpty() method checks whether the g 1 min read Hashtable isEmpty() Method in Java The Hashtable.isEmpty() method is a built-in method of the java.util.Hashtable class. This method is used to check if the table is empty or not. The method returns true, if no key-value pair or mapping is present in the table, else it returns false.Syntax of Hashtable isEmpty() Methodhash_table.isEm 2 min read IdentityHashMap isEmpty() Method in Java The java.util.IdentityHashMap.isEmpty() method of IdentityHashMap class is used to check for the emptiness of the map. The method returns True if no key-value pair or mapping is present in the map else False. Syntax: Identity_Hash_Map.isEmpty()Parameters: The method does not take any parameters. Ret 2 min read ConcurrentHashMap isEmpty() Method in Java The isEmpty() method in Java's ConcurrentHashMap class is used to check whether the map is empty or not. It has the following signature: boolean isEmpty() The isEmpty() method works in a concurrent environment, which means that it can be called from multiple threads without causing any data race or 2 min read BitSet isEmpty() method in Java BitSet is a class defined in the java.util package. It creates an array of bits represented by boolean values. Prerequisite : Java BitSet | Set 1 Bitset.isEmpty() This method is used to check if there are any bits that are set to true, in the specified BitSet. This method returns true if this BitSet 2 min read ArrayDeque isEmpty() Method in Java The Java.util.ArrayDeque.isEmpty() method in Java is used to check and verify if an ArrayDeque is empty or not. It returns True if the Deque is empty else it returns False. Syntax: Array_Deque.isEmpty() Parameters: The method does not take any parameter. Return Value: The function returns True if th 2 min read Like