ConcurrentLinkedDeque contains() method in Java with Examples
The java.util.concurrent.ConcurrentLinkedDeque.contains() method is 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 elem which checks if the specified element is present in the deque or not.
Return Value: The function returns True if the element is present in the deque and returns False otherwise.
Below programs illustrate the ConcurrentLinkedDeque.contains() method:
Program 1:
// 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"); } } } |
ConcurrentLinkedDeque: [Welcome, To, Geeks, 4, Geeks] GFG is not present
Program 2:
// 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"); } } } |
ConcurrentLinkedDeque: [Welcome, To, Geeks, 4, Geeks] Geeks is present
Recommended Posts:
- ConcurrentLinkedDeque pop() method in Java with Examples
- ConcurrentLinkedDeque isEmpty() method in Java with Examples
- ConcurrentLinkedDeque push() method in Java with Examples
- ConcurrentLinkedDeque addAll() method in Java with Examples
- ConcurrentLinkedDeque Spliterator() method in Java with Examples
- ConcurrentLinkedDeque remove() method in Java with Examples
- ConcurrentLinkedDeque offer() method in Java with Examples
- ConcurrentLinkedDeque in Java with Examples
- ConcurrentLinkedDeque add() method in Java
- ConcurrentLinkedDeque removeFirst() method in Java
- ConcurrentLinkedDeque pollLast() method in Java
- ConcurrentLinkedDeque peekFirst() method in Java
- ConcurrentLinkedDeque peek() method in Java with Example
- ConcurrentLinkedDeque removeLastOccurrence() Method in Java
- ConcurrentLinkedDeque iterator() method in Java with Example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



