Skip to content
Related Articles

Related Articles

LinkedTransferQueue isEmpty() method in Java
  • Last Updated : 14 Sep, 2018

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()

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :