Java PriorityQueue clear() methodLast Updated : 17 Mar 2025 The clear() method of PriorityQueue class Removes all the elements from this priority queue. After calling this method, the queue will be empty. SyntaxParameterNA Specified ByThe clear() method of class PriorityQueue is specified by clear() method in interface Collection<E>. OverrideThe clear() method of class PriorityQueue overrides the clear() method of class AbstractQueue<E>. Example 1Output: Course : [C, C++, Java, Python] After clearing the queue : [] Example 2Output: 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-comparator-method |
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India