ConcurrentHashMap isEmpty() Method in Java
The isEmpty() method of java.util.concurrent.ConcurrentHashMap is an in-built function in Java which checks if this map contains any key-value mappings and returns a boolean value.
Syntax:
public boolean isEmpty()
Return Value: The function returns a boolean value. It returns true if the ConcurrentHashMap is empty and returns false otherwise.
Below programs illustrate the use of isEmpty() method :
Program 1: In this program the ConcurrentHashMap is non-empty.
// Java Program Demonstrate isEmpty() // method of ConcurrentHashMap */ import java.util.concurrent.*; class ConcurrentHashMapDemo { public static void main(String[] args) { ConcurrentHashMap<Integer, String> chm = new ConcurrentHashMap<Integer, String>(); chm.put(100, "Geeks"); chm.put(101, "for"); chm.put(102, "Geeks"); // Checking for the emptiness of Map if (chm.isEmpty()) { System.out.println("The ConcurrentHashMap" + " is empty."); } else { // Displaying the ConcurrentHashMap System.out.println("The Mappings are: " + chm); } } } |
The Mappings are: {100=Geeks, 101=for, 102=Geeks}
Program 2:In this program the ConcurrentHashMap is non-empty.
// Java Program Demonstrate isEmpty() // method of ConcurrentHashMap */ import java.util.concurrent.*; class GFG { public static void main(String[] args) { ConcurrentHashMap chm = new ConcurrentHashMap(); // Checking for the emptiness of Map if (chm.isEmpty()) { System.out.println("The ConcurrentHashMap" + " is empty."); } else { // Displaying the ConcurrentHashMap System.out.println("The Mappings are: " + chm); } } } |
The ConcurrentHashMap is empty.
Reference : https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ConcurrentHashMap.html#isEmpty()
Recommended Posts:
- ConcurrentHashMap put() method in Java
- ConcurrentHashMap get() Method in Java
- ConcurrentHashMap size() Method in Java
- ConcurrentHashMap containsValue() Method in Java
- ConcurrentHashMap contains() method in Java with Examples
- ConcurrentHashMap remove() method in Java
- ConcurrentHashMap containsKey() Method in Java
- ConcurrentHashMap putIfAbsent() Method in Java
- ConcurrentHashMap putAll() method in Java
- ConcurrentHashMap elements() method in Java with Examples
- ConcurrentHashMap keys() method in Java with Examples
- ConcurrentHashMap computeIfAbsent() method in Java with Examples
- ConcurrentHashMap compute() method in Java with Examples
- ConcurrentHashMap keySet() method in Java with Examples
- ConcurrentHashMap entrySet() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



