Thursday, December 11, 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
32440 POSTS0 COMMENTS
Milvus
105 POSTS0 COMMENTS
Nango Kala
6811 POSTS0 COMMENTS
Nicole Veronica
11950 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12023 POSTS0 COMMENTS
Shaida Kate Naidoo
6943 POSTS0 COMMENTS
Ted Musemwa
7195 POSTS0 COMMENTS
Thapelo Manthata
6889 POSTS0 COMMENTS
Umr Jansen
6880 POSTS0 COMMENTS