Monday, November 18, 2024
Google search engine
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

Recent Comments