ConcurrentLinkedQueue isEmpty() method in Java
The isEmpty() method of ConcurrentLinkedQueue is used to check if this queue is empty or not. It returns true if ConcurrentLinkedQueue contains zero number of elements means if the ConcurrentLinkedQueue is empty.
Syntax:
public boolean isEmpty()
Returns: This method returns true if this ConcurrentLinkedQueue contains zero number of elements.
Below programs illustrate isEmpty() method of ConcurrentLinkedQueue:
Example 1:
// Java Program Demonstrate isEmpty() // method of ConcurrentLinkedQueue import java.util.concurrent.*; public class GFG { public static void main(String[] args) { // create an ConcurrentLinkedQueue ConcurrentLinkedQueue<String> queue = new ConcurrentLinkedQueue<String>(); // Add String to queue queue.add("Aman"); queue.add("Amar"); queue.add("Sanjeet"); queue.add("Rabi"); // Displaying the existing ConcurrentLinkedQueue System.out.println("ConcurrentLinkedQueue: " + queue); // check whether queue isEmpty or not boolean response1 = queue.isEmpty(); // print after applying isEmpty method System.out.println("Is Queue empty: " + response1); } } |
ConcurrentLinkedQueue: [Aman, Amar, Sanjeet, Rabi] Is Queue empty: false
Example 2:
// Java Program Demonstrate isEmpty() // method of ConcurrentLinkedQueue import java.util.concurrent.*; public class GFG { public static void main(String[] args) { // create an ConcurrentLinkedQueue ConcurrentLinkedQueue<Integer> queue = new ConcurrentLinkedQueue<Integer>(); // Displaying the existing ConcurrentLinkedQueue System.out.println("ConcurrentLinkedQueue: " + queue); // check whether queue is Empty boolean response1 = queue.isEmpty(); // print after applying isEmpty method System.out.println("Is queue empty : " + response1); } } |
ConcurrentLinkedQueue: [] Is queue empty : true
Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html#isEmpty–
Recommended Posts:
- ConcurrentLinkedQueue contains() method in Java
- ConcurrentLinkedQueue add() method in Java
- ConcurrentLinkedQueue toArray() Method in Java
- ConcurrentLinkedQueue peek() method in Java
- ConcurrentLinkedQueue size() method in Java
- ConcurrentLinkedQueue poll() method in Java
- ConcurrentLinkedQueue spliterator() method in Java
- ConcurrentLinkedQueue remove() method in Java
- ConcurrentLinkedQueue addAll() method in Java
- ConcurrentLinkedQueue iterator() method in Java
- ConcurrentLinkedQueue offer() method in Java
- ConcurrentSkipListSet isEmpty() method in Java
- IdentityHashMap isEmpty() Method in Java
- LinkedHashSet isEmpty() method in Java
- Map isEmpty() 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.



