Java PriorityQueue add() methodThe 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 1Test it NowOutput: Course : C Course : C++ Course : Java Course : Python Example 2Test it NowOutput: 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 3Test it NowOutput: Elements are : 800 1190 1178 7118 Max element = 7118 Min element = 800
Next TopicJava PriorityQueue
|