Online Java Compiler By
JavaTpoint.com
import java.util.PriorityQueue; public class PriorityQueuePeekExample1 { public static void main(String[] args) { PriorityQueue
Pqueue = new PriorityQueue
(); Pqueue.add(25); Pqueue.add(65); Pqueue.add(56); Pqueue.add(98); Integer val = Pqueue.peek(); System.out.println("Head of queue is: "+val); System.out.println("Queue after using peek() method : "); for(Integer xyz : Pqueue) { System.out.println(xyz); } } }
Output