BACK
This Program is used for retrieving, but does not remove, the head of this queue, or returns null if this queue is empty using Peek() method.
Example Program
import java.util.PriorityQueue; import java.util.comparator; public class PriorityQ { public static void main(String[] args) { PriorityQueue<Integer> PQ = new PriorityQueue<Integer>(); PQ.add(100); PQ.add(12); PQ.add(56); PQ.add(89); PQ.add(103); System.out.println("The default way:"); for (Integer number : PQ) { System.out.println(number); } System.out.println("The head of this list is: " + PQ.peek()); } }
Output
The default way:
12
89
56
100
103
The head of this list is: 12
Specified by:
Returns:
the head of this queue, or null if this queue is empty.