Java Collection Tutorial - Java PriorityQueue.add(E e)


PriorityQueue.add(E e) has the following syntax.

public boolean add(E e)


In the following code shows how to use PriorityQueue.add(E e) method.

//from w w  w. j  av  a2  s  .c o  m

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.