Java PriorityQueue offer() MethodThe offer() method of the PriorityQueue class is used to insert the specified element into this priority queue. SyntaxParametere - It is the element to be added. Specified ByThe offer() method of the PrioriryQueue class is specified by offer() method n interface Queue<E>. Return ValueThe offer() method returns true same as defined by Queue.offer(E). ThrowsThe offer() method throws:
Example 1Output: Priority Queue values are: [5, 6, 7, 8, 9, 10, 11, 12, 13, 14] Priority Queue values after addition are: [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 25] Example 2Output: Priority Queue values are: [Aman, Asif, Dimple, Dhanil, Deepak, Harshit, Jass, Harman] Exception in thread "main" java.lang.NullPointerException Example 3Output: Amit Barun Raj Simran Next TopicJava-priorityqueue-peek-method |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India