The contains(Object o) method of LinkedBlockingDeque checks if the passed element in the parameter exists in the container or not. It returns true if the element exists in the container else it returns a false value.
Syntax:
public boolean contains(Object o)
Parameters: This method accepts a mandatory parameter o whose presence in the container is to be checked in the container.
Returns: This method returns true if the element is present, else it returns false.
Below programs illustrate contains() method of LinkedBlockingDeque:
Program 1:
// Java Program Demonstrate contains() // method of LinkedBlockingDeque import java.util.concurrent.LinkedBlockingDeque; import java.util.*; public class GFG { public static void main(String[] args) throws IllegalStateException { // create object of LinkedBlockingDeque LinkedBlockingDeque<Integer> LBD = new LinkedBlockingDeque<Integer>(); // Add numbers to end of LinkedBlockingDeque LBD.add(10); LBD.add(20); LBD.add(30); LBD.add(40); // before removing print queue System.out.println("Linked Blocking Deque: " + LBD); // check for presence using function if (LBD.contains(10)) { System.out.println("Linked Blocking Deque contains 10"); } else { System.out.println("Linked Blocking Deque does not contain 10"); } } } |
Linked Blocking Deque: [10, 20, 30, 40] Linked Blocking Deque contains 10
Program 2:
// Java Program Demonstrate contains() // method of LinkedBlockingDeque import java.util.concurrent.LinkedBlockingDeque; import java.util.*; public class GFG { public static void main(String[] args) throws IllegalStateException { // create object of LinkedBlockingDeque LinkedBlockingDeque<String> LBD = new LinkedBlockingDeque<String>(); // Add numbers to end of LinkedBlockingDeque LBD.add("ab"); LBD.add("cd"); LBD.add("fg"); LBD.add("xz"); // before removing print queue System.out.println("Linked Blocking Deque: " + LBD); // check for presence using function if (LBD.contains("go")) { System.out.println("Linked Blocking Deque contains 'go'"); } else { System.out.println("Linked Blocking Deque does not contain 'go'"); } } } |
Linked Blocking Deque: [ab, cd, fg, xz] Linked Blocking Deque does not contain 'go'
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
Recommended Posts:
- LinkedBlockingDeque putFirst() method in Java
- LinkedBlockingDeque getFirst() method in Java
- LinkedBlockingDeque iterator() method in Java
- LinkedBlockingDeque getLast() method in Java
- LinkedBlockingDeque removeLastOccurrence() method in Java
- LinkedBlockingDeque size() method in Java
- LinkedBlockingDeque clear() method in Java
- LinkedBlockingDeque addLast() method in Java
- LinkedBlockingDeque add() method in Java
- LinkedBlockingDeque addFirst() method in Java
- LinkedBlockingDeque push() method in Java
- LinkedBlockingDeque pop() method in Java
- LinkedBlockingDeque offer() method in Java
- LinkedBlockingDeque offerLast() method in Java
- LinkedBlockingDeque peek() method in Java
- LinkedBlockingDeque peekLast() method in Java
- LinkedBlockingDeque poll() method in Java
- LinkedBlockingDeque pollFirst() method in Java
- LinkedBlockingDeque pollLast() method in Java
- LinkedBlockingDeque descendingIterator() method in Java
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.

