Java PriorityQueue peek() MethodThe peek() method of PriorityQueue class retrieves the head of this queue but doesn't remove it. The method returns null if this queue is empty. SyntaxParameterNA Return ValueThe peek() method returns this queue's head, and if this queue is empty, returns null. Example 1Test it NowOutput: Head of queue is: 25 Queue after using peek() method : 25 65 56 98 Example 2Test it NowOutput: Head of queue is: null Example 3Test it NowOutput: The winner of Lottery Prize is Sham with lottery number 123456
Next TopicJava PriorityQueue
|