Java PriorityQueue add() methodLast Updated : 17 Mar 2025 The add() method of the PriorityQueue class is used to insert the specified element into this priority queue. SyntaxParametere - It is the element to be added OverrideThe add() method of class PriorityQueue overrides the add() method of class AbstractQueue<E>. Return ValueThe add() method returns true(as specified by Collection.add(E)). ThrowsThe add() method throws :
Example 1Output: Course : C Course : C++ Course : Java Course : Python 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 Example 3Output: Elements are : 800 1190 1178 7118 Max element = 7118 Min element = 800 Next TopicJava-priorityqueue-clear-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