Thursday, September 4, 2025
HomeLanguagesJavaLinkedTransferQueue contains() method in Java

LinkedTransferQueue contains() method in Java

The contains() method of java.util.concurrent.LinkedTransferQueue is an in-built function in Java which returns a true boolean value if the specified element is present in this queue otherwise it returns false.

Syntax:

LinkedTransferQueue.contains(Object o)

Parameters: The function accepts a single parameter o i.e. to be checked for the presence in this queue.

Return Value: The function returns a Boolean value. It returns True if the specified element is present in this queue else it returns False.

Below programs illustrate the LinkedTransferQueue.contains() method:

Program 1:




// Java Program Demonstrate contains()
// method of LinkedTransferQueue
  
import java.util.concurrent.*;
  
class LinkedTransferQueueContainsExample1 {
    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 9 is present in the queue
        if (queue.contains(9))
            System.out.println("9 is present in the queue.");
        else
            System.out.println("9 is not present in the queue.");
    }
}


Output:

9 is not present in the queue.

Program 2:




// Java Program Demonstrate contains()
// method of LinkedTransferQueue */
  
import java.util.concurrent.*;
  
class LinkedTransferQueueContainsExample2 {
    public static void main(String[] args)
    {
  
        // Initializing the queue
        LinkedTransferQueue<String>
            queue = new LinkedTransferQueue<String>();
  
        // Adding elements to this queue
        queue.add("Gfg");
        queue.add("is");
        queue.add("fun");
  
        // Checks if Gfg is present in the queue
        if (queue.contains("Gfg"))
            System.out.println("Gfg is present in the queue.");
        else
            System.out.println("Gfg is not present in the queue.");
    }
}


Output:

Gfg is present in the queue.

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

RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6629 POSTS0 COMMENTS
Nicole Veronica
11799 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11858 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6698 POSTS0 COMMENTS
Umr Jansen
6716 POSTS0 COMMENTS