Open In App

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:
Output:
Blocking Queue: [10, 20, 30, 40]
Blocking Queue contains 10
Program 2:
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)

Similar Reads