Java PriorityQueue peek() Method
Java PriorityQueue peek() Method
Last Updated : 17 Mar 2025
The 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.
Syntax
Parameter
NA
Return Value
The peek() method returns this queue's head, and if this queue is empty, returns null.
Example 1
Output:
Head of queue is: 25 Queue after using peek() method : 25 65 56 98
Example 2
Output:
Head of queue is: null
Example 3
Output:
The winner of Lottery Prize is Sham with lottery number 123456
Next TopicJava-priorityqueue-poll-method