BlockingDeque contains() method in Java with Examples
Last Updated :
01 Oct, 2019
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:
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.BlockingDeque;
import java.util.*;
public class GFG {
public static void main(String[] args)
throws IllegalStateException
{
BlockingDeque<Integer> BD
= new LinkedBlockingDeque<Integer>();
BD.add( 10 );
BD.add( 20 );
BD.add( 30 );
BD.add( 40 );
System.out.println( "Blocking Deque: " + BD);
if (BD.contains( 10 )) {
System.out.println( "Blocking Deque contains 10" );
}
else {
System.out.println( "Blocking Deque does not contain 10" );
}
}
}
|
Output:
Blocking Deque: [10, 20, 30, 40]
Blocking Deque contains 10
Program 2:
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.BlockingDeque;
import java.util.*;
public class GFG {
public static void main(String[] args)
throws IllegalStateException
{
BlockingDeque<String> BD
= new LinkedBlockingDeque<String>();
BD.add( "ab" );
BD.add( "cd" );
BD.add( "fg" );
BD.add( "xz" );
System.out.println( "Blocking Deque: " + BD);
if (BD.contains( "go" )) {
System.out.println( "Blocking Deque contains 'go'" );
}
else {
System.out.println( "Blocking Deque does not contain 'go'" );
}
}
}
|
Output:
Blocking Deque: [ab, cd, fg, xz]
Blocking Deque does not contain 'go'
Reference: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/LinkedBlockingDeque.html#contains(java.lang.Object)
Share your thoughts in the comments
Please Login to comment...