Javatpoint Logo
Javatpoint Logo

Java PriorityQueue remove() Method

The remove() method of PriorityQueue class removes a single instance of the specified element from this queue, only if it is present.

Syntax

Parameter

o - It is the element to be eliminated from this queue.

Specified By

The remove() method of the PriorityQueue class is specified by remove() method in interface Collection<E>.

Override

The remove() method of the PriorityQueue class is override by remove() method in class AbstractCollection<E>.

Return Value

The remove() method returns true if this queue is changed after the call.

Example 1

Test it Now

Output:

Queue before using remove() method :
Adam
Ahana
Chris
Rafiq
Amir
Queue after using remove() method :true
Adam
Ahana
Amir
Rafiq

Example 2

Test it Now

Output:

Queue before using remove() method :
45
67
56
98
73
Queue after using remove() method :false
45
67
56
98
73

Example 3

Test it Now

Output:

Patients are : [Amar, Mukta, Aloke]
Patients left : [Amar, Aloke]

Example 4

Test it Now

Output:

Elements in queue = [1, 2, 3]
Element removed = 1
Elements left in queue = [2, 3]
Element removed = 2
Elements left in queue = [3]
Next TopicJava PriorityQueue



Help Others, Please Share

facebook twitter pinterest