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.
Syntax:
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:
Program 1:
Output:
Queue: [1, 2, 3, 4]
2 removed: true
Queue: [1, 4, 3]
5 removed: false
Queue: [1, 4, 3]
Output:
Queue: [A Computer, Portal, Geeks, forGeeks]
Geeks removed: true
Queue: [A Computer, Portal, forGeeks]
SandeepJain removed: false
Queue: [A Computer, Portal, forGeeks]