BlockingDeque contains() method in Java with Examples
The contains(Object o) method of BlockingDeque 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.
Note: The contains() method of BlockingDeque has been inherited from the LinkedBlockingDeque class in Java.
Below programs illustrate contains() method of BlockingDeque:
Program 1:
// Java Program Demonstrate contains() // method of BlockingDeque import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.BlockingDeque; import java.util.*; public class GFG { public static void main(String[] args) throws IllegalStateException { // create object of BlockingDeque BlockingDeque<Integer> BD = new LinkedBlockingDeque<Integer>(); // Add numbers to end of BlockingDeque BD.add( 10 ); BD.add( 20 ); BD.add( 30 ); BD.add( 40 ); // before removing print Deque System.out.println( "Blocking Deque: " + BD); // check for presence using function if (BD.contains( 10 )) { System.out.println( "Blocking Deque contains 10" ); } else { System.out.println( "Blocking Deque does not contain 10" ); } } } |
Blocking Deque: [10, 20, 30, 40] Blocking Deque contains 10
Program 2:
// Java Program Demonstrate contains() // method of BlockingDeque import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.BlockingDeque; import java.util.*; public class GFG { public static void main(String[] args) throws IllegalStateException { // create object of BlockingDeque BlockingDeque<String> BD = new LinkedBlockingDeque<String>(); // Add numbers to end of BlockingDeque BD.add( "ab" ); BD.add( "cd" ); BD.add( "fg" ); BD.add( "xz" ); // before removing print Deque System.out.println( "Blocking Deque: " + BD); // check for presence using function if (BD.contains( "go" )) { System.out.println( "Blocking Deque contains 'go'" ); } else { System.out.println( "Blocking Deque does not contain 'go'" ); } } } |
Blocking Deque: [ab, cd, fg, xz] Blocking Deque does not contain 'go'
Recommended Posts:
- BlockingDeque put() method in Java with Examples
- BlockingDeque add() method in Java with Examples
- BlockingDeque take() method in Java with Examples
- BlockingDeque removeLastOccurrence() method in Java with Examples
- BlockingDeque takeLast() method in Java with Examples
- BlockingDeque putFirst() method in Java with Examples
- BlockingDeque takeFirst() method in Java with Examples
- BlockingDeque pollFirst() method in Java with examples
- BlockingDeque peek() method in Java with examples
- BlockingDeque poll() method in Java with examples
- BlockingDeque pollLast() method in Java with examples
- BlockingDeque offerLast() method in Java with examples
- BlockingDeque element() method in java with examples
- BlockingDeque addLast() method in Java with Examples
- BlockingDeque addFirst() method in Java with Examples
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.