Last Updated on March 11, 2022 by Ria Pathak
Introduction
ConcurrentLinkedQueue class in java extends AbstractQueue interface and implements Queue interface. This class was added in Java 5. ConcurrentLinkedQueue class is a member of the collections framework in java.
ConcurrentLinkedQueue class is a thread-safe queue which is unbounded. It is based on linked nodes. This queue follows the FIFO principle. This queue orders elements in FIFO (first-in-first-out) order.
Please check out this article to learn more about ConcurrentLinkedQueue.
ConcurrentLinkedQueue isEmpty() method
This method is used to check whether a queue is empty or not:
- If the ConcurrentLinkedQueue is empty (contain zero number of element), then it will return true.
- Else, it will return false.
Syntax:
public boolean isEmpty()
Return Value:
It will return true when the concurrentLinkedQueue is empty, otherwise false.
Example 1
import java.util.concurrent.*; public class Prepbytes { public static void main(String[] args) { ConcurrentLinkedQueue queue = new ConcurrentLinkedQueue(); queue.add(1); queue.add(2); queue.add(3); queue.add(4); System.out.println("Original ConcurrentLinkedQueue: " + queue); boolean check = queue.isEmpty(); System.out.println("Is Empty: " + check); } }
Output
Original ConcurrentLinkedQueue: [1, 2, 3, 4]
Is Empty: false
Example 2
import java.util.concurrent.*; public class Pepbytes { public static void main(String[] args) { ConcurrentLinkedQueue queue = new ConcurrentLinkedQueue(); System.out.println("Original ConcurrentLinkedQueue: " + queue); boolean check = queue.isEmpty(); System.out.println("Is Empty : " + check); } }
Output
Original ConcurrentLinkedQueue: []
Is Empty : true
So, in this blog, we have tried to explain the ConcurrentLinkedQueue isEmpty() method in Java with examples. Java Collection Framework is very important when it comes to coding interviews. If you want to solve more questions on Linked List, which are curated by our expert mentors at PrepBytes, you can follow this link Linked List.