Javatpoint Logo
Javatpoint Logo

Java PriorityQueue clear() method

The clear() method of PriorityQueue class Removes all the elements from this priority queue. After calling this method, the queue will be empty.

Syntax

Parameter

NA

Specified By

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

Override

The clear() method of class PriorityQueue overrides the clear() method of class AbstractQueue<E>.

Example 1

Test it Now

Output:

Course : [C, C++, Java, Python]
After clearing the queue :
[]

Example 2

Test it Now

Output:

1 Roll No = 2
 Name = ravi
 Course = C
 Age = 21

2 Roll No = 1
 Name = Geetanjali
 Course = Java
 Age = 21

3 Roll No = 3
 Name = HimanshuBhardwaj
 Course = C++
 Age = 21

After clearing the queue :
 []
Next TopicJava PriorityQueue



Help Others, Please Share

facebook twitter pinterest