Java PriorityQueue.poll()

Syntax

PriorityQueue.poll() has the following syntax.

public E poll()

Example

In the following code shows how to use PriorityQueue.poll() method.


import java.util.PriorityQueue;
// www.  j  a  v a 2s  . c  o  m
public class Main {
   public static void main(String args[]) {

      PriorityQueue<Integer>   prq = new PriorityQueue<Integer>(); 
       
      for ( int i = 3; i < 10; i++ ){  
         prq.add (i) ; 
      }
      
      System.out.println(prq);
      
      // get the head from the queue
      Integer head = prq.poll();
      
      System.out.println ( "Head of the queue is: "+ head);
      
      System.out.println(prq);
   }
}

The code above generates the following result.