ArrayBlockingQueue remove() 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 remove(Object o) method removes a single instance of the specified element from this queue, if it is present.
We can say that method removes an element e such that o.equals(e) if this queue contains one or more such elements. Remove() method returns true if this queue contained the specified element which we want to remove.
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 remove(Object o)
o – element to be removed from this queue, if present.
returns true if this queue contained the specified element which we want to remove.
Below program illustrate remove(Object o) method of ArrayBlockingQueue.
Output : queue contains [223, 546, 986] Removal of 223 :true queue contains [546, 986] Removal of 546 :true queue contains  Removal of 734 :false queue contains 
Output : queue contains [StarWars, SuperMan, Flash, BatMan, Avengers] Removal of StarWars :true queue contains [SuperMan, Flash, BatMan, Avengers] Removal of Hulk :false queue contains [SuperMan, Flash, BatMan, Avengers]