PriorityBlockingQueue contains() method in Java
The contains(Object o) method checks whether PriorityBlockingQueue contains an object o or not. This method returns true, if and only if, this queue contains at least one element e which is equal to object o passed as parameter i.e. e.equals(o). If queue does not contains the Object o, then method returns false.
public boolean contains(Object o)
Parameter: This method takes a mandatory parameter o which is the object to be checked in the PriorityBlockingQueue.
Returns: This method returns true if this queue contains the object passed as parameter. Else it returns false.
Exception: This method does not throw any Exception.
Below program illustrate contains() method of PriorityBlockingQueue:
PrioQueue: [56156, 46514561, 4641515, 948964165] PriorityBlockingQueue contains number 56156 : true PriorityBlockingQueue contains number 46545 : false
Example 2: To demonstrate contains() method of PriorityBlockingQueue which contains list of names.
List of Names: [A, Computer, Geeks, forGeeks, Portal] Does names contains Geeks: true Does names contains SandeepJain: false
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.