Java PriorityQueue() Constructor

Syntax

PriorityQueue() constructor from PriorityQueue has the following syntax.

public PriorityQueue()

Example

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


/*from w w  w  .j  a  va  2s  . c  om*/
import java.util.PriorityQueue;

public class Main {
   public static void main(String args[]) {

      PriorityQueue<Integer>   prq = new PriorityQueue<Integer>() ; 
       
      for ( int i = 0; i < 10; i++ ){  
         prq.add (i) ; 
      }      
      System.out.println(prq) ; 
   }
}

The code above generates the following result.