Thursday, October 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
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS