BlockingQueue contains() method in Java with examples Last Updated : 14 Oct, 2019 Comments Improve Suggest changes Like Article Like Report The contains(Object o) method of BlockingQueue interface 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 BlockingQueue has been inherited from the Queue class in Java. Below programs illustrate contains() method of BlockingQueue: Program 1: Java // Java Program Demonstrate contains() // method of BlockingQueue import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.BlockingQueue; import java.util.*; public class GFG { public static void main(String[] args) throws IllegalStateException { // create object of BlockingQueue BlockingQueue<Integer> BQ = new LinkedBlockingQueue<Integer>(); // Add numbers to end of BlockingQueue BQ.add(10); BQ.add(20); BQ.add(30); BQ.add(40); // before removing print queue System.out.println("Blocking Queue: " + BQ); // check for presence using function if (BQ.contains(10)) { System.out.println("Blocking Queue contains 10"); } else { System.out.println("Blocking Queue does not contain 10"); } } } Output: Blocking Queue: [10, 20, 30, 40] Blocking Queue contains 10 Program 2: Java // Java Program Demonstrate contains() // method of BlockingQueue import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.BlockingQueue; import java.util.*; public class GFG { public static void main(String[] args) throws IllegalStateException { // create object of BlockingQueue BlockingQueue<String> BQ = new LinkedBlockingQueue<String>(); // Add numbers to end of BlockingQueue BQ.add("ab"); BQ.add("cd"); BQ.add("fg"); BQ.add("xz"); // before removing print queue System.out.println("Blocking Queue: " + BQ); // check for presence using function if (BQ.contains("go")) { System.out.println("Blocking Queue contains 'go'"); } else { System.out.println("Blocking Queue does not contain 'go'"); } } } Output: Blocking Queue: [ab, cd, fg, xz] Blocking Queue does not contain 'go' Reference: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/LinkedBlockingQueue.html#contains(java.lang.Object) Comment More infoAdvertise with us Next Article BlockingQueue contains() method in Java with examples G gopaldave Follow Improve Article Tags : Java Java-Collections Java-Functions Java-BlockingQueue Practice Tags : JavaJava-Collections Similar Reads 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 par 2 min read Collection contains() method in Java with Examples The contains(Object element) of java.util.Collection interface is used to check whether the element 'element' exists in this collection. This method returns a boolean value depicting the presence of the element. If the element is present, it returns true, else it returns false. Syntax: Collection.co 3 min read Charset contains() method in Java with Examples The contains() method is a built-in method of the java.nio.charset checks if a given charset is in another given charset. A charset X contains a charset Y if every character representable in Y is also representable in X. Every charset contains itself. However, this method computes an approximation o 2 min read 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 2 min read AbstractSet contains() method in Java with Example The contains() method of Java AbstractSet is used to check whether an element is present in a set or not. It takes the element as a parameter and returns True if the element is present in the set. Syntax: public boolean contains(Object element) Parameters: The parameter element is of type set. This 2 min read Like