ArrayBlockingQueue contains() method in Java
ArrayBlockingQueue is bounded, blocking queue that stores the elements internally backed by an array.
- ArrayBlockingQueue class is a member of the Java Collections Framework.
- Bounded means it will have a fixed size, you can not store number the elements more than the capacity of the queue.
- The queue also follows FIFO (first-in-first-out) rule for storing and removing elements from the queue.
- If you try to put an element into a full queue or to take an element from an empty queue then the queue will block you.
The contains(Object o) method returns true if queue contains the object o passed as parameter. We can say that 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. o.equals(e).
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.
public boolean contains(Object o)
o – object to check whether queue contains the specified object.
true if this queue contains the object
Below program illustrate contains method of ArrayBlockingQueue.
queue contains 23 : true queue contains 99 : false
queue contains User having name Aman : true queue contains User having name Ravi : false