The remove(Object o) method of PriorityBlockingQueue is used to delete an element from this queue. This method removes a single instance of the element passed as the parameter, if it is present.
It returns true if and only if the element was removed, else it returned false.
public boolean remove(Object o)
Parameter: This method accepts a mandatory parameter o which is the element to be removed from this queue, if present.
Return Value: This method returns true if the specified element was removed successfully. Else this method returns false.
Below programs illustrate remove() method in PriorityBlockingQueue:
Queue: [1, 2, 3, 4] 2 removed: true Queue: [1, 4, 3] 5 removed: false Queue: [1, 4, 3]
Queue: [A Computer, Portal, Geeks, forGeeks] Geeks removed: true Queue: [A Computer, Portal, forGeeks] SandeepJain removed: false Queue: [A Computer, Portal, forGeeks]
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.