Last Updated : 11 Jul, 2025
The
java.util.concurrent.ConcurrentLinkedDeque.contains() methodis an inbuilt method in Java which checks if the specified element, passed as a parameter, is present in the deque or not.
Syntax:public boolean contains(Object elem)Parameters:
The method accepts a parameter
elemwhich checks if the specified element is present in the deque or not.
Return Value:The function returns
Trueif the element is present in the deque and returns
Falseotherwise. Below programs illustrate the
ConcurrentLinkedDeque.contains()method:
Program 1:
Java
// Java Program to Demonstrate contains()
// method of ConcurrentLinkedDeque
import java.util.concurrent.*;
class GFG {
public static void main(String[] args)
{
// Creating an empty Deque
ConcurrentLinkedDeque<String> cld = new ConcurrentLinkedDeque<String>();
// Add elements into the Deque
cld.add("Welcome");
cld.add("To");
cld.add("Geeks");
cld.add("4");
cld.add("Geeks");
// Displaying the Deque
System.out.println("ConcurrentLinkedDeque: "
+ cld);
// Check if GFG is present using contains()
if (cld.contains("GFG")) {
// Displaying message
System.out.println("GFG is present");
}
else {
// Displaying message
System.out.println("GFG is not present");
}
}
}
Output:
ConcurrentLinkedDeque: [Welcome, To, Geeks, 4, Geeks] GFG is not presentProgram 2: Java
// Java Program to Demonstrate contains()
// method of ConcurrentLinkedDeque
import java.util.concurrent.*;
class GFG {
public static void main(String[] args)
{
// Creating an empty Deque
ConcurrentLinkedDeque<String> cld = new ConcurrentLinkedDeque<String>();
// Add elements into the Deque
cld.add("Welcome");
cld.add("To");
cld.add("Geeks");
cld.add("4");
cld.add("Geeks");
// Displaying the Deque
System.out.println("ConcurrentLinkedDeque: "
+ cld);
// Check if Geeks is present using contains()
if (cld.contains("Geeks")) {
// Displaying message
System.out.println("Geeks is present");
}
else {
// Displaying message
System.out.println("Geeks not present");
}
}
}
Output:
ConcurrentLinkedDeque: [Welcome, To, Geeks, 4, Geeks] Geeks is presentReference: https://docs.oracle.com/javase/9/docs/api/java/util/concurrent/ConcurrentLinkedDeque.html#contains-java.lang.Object-
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4