Sunday, November 23, 2025
HomeLanguagesJavaLinkedTransferQueue isEmpty() method in Java

LinkedTransferQueue isEmpty() method in Java

The isEmpty() method of java.util.concurrent.LinkedTransferQueue is an in-built function in Java which checks if this queue is empty or not.

Syntax:

LinkedTransferQueue.isEmpty()

Return Value: The function returns a boolean value. It returns true if the LinkedTransferQueue is empty and returns false otherwise.

Below programs illustrate the LinkedTransferQueue.isEmpty() method:

Program 1: In this program the LinkedTransferQueue is non-empty.




// Java Program Demonstrate isEmpty()
// method of LinkedTransferQueue
  
import java.util.concurrent.*;
  
class LinkedTransferQueueIsEmptyExample1 {
    public static void main(String[] args)
    {
  
        // Initializing the queue
        LinkedTransferQueue<Integer>
            queue = new LinkedTransferQueue<Integer>();
  
        // Adding elements to this queue
        for (int i = 10; i <= 15; i++)
            queue.add(i);
  
        // Checks if this queue is empty or not
        if (queue.isEmpty())
            System.out.println("The queue is empty.");
        else
            System.out.println("The queue is non-empty.");
    }
}


Output:

The queue is non-empty.

Program 2:In this program the LinkedTransferQueue is empty.




// Java Program Demonstrate isEmpty()
// method of LinkedTransferQueue */
  
import java.util.concurrent.*;
  
class LinkedTransferQueueIsEmptyExample2 {
    public static void main(String[] args)
    {
  
        // Initializing the queue
        LinkedTransferQueue<Integer>
            queue = new LinkedTransferQueue<Integer>();
  
        // Checks if this queue is empty or not
        if (queue.isEmpty())
            System.out.println("The queue is empty.");
        else
            System.out.println("The queue is non-empty.");
    }
}


Output:

The queue is empty.

Reference: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/LinkedTransferQueue.html#isEmpty()

RELATED ARTICLES

Most Popular

Dominic
32407 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6785 POSTS0 COMMENTS
Nicole Veronica
11932 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12000 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7168 POSTS0 COMMENTS
Thapelo Manthata
6864 POSTS0 COMMENTS
Umr Jansen
6852 POSTS0 COMMENTS