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

Output:

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

Example 2

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 :
 []