Java PriorityQueue.size()

Syntax

PriorityQueue.size() has the following syntax.

public int size()

Example

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


/*from   ww  w  .j av a  2  s.  com*/

import java.util.PriorityQueue;

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 ( "Size of the queue is: "+ prq.size());
      
      System.out.println(prq);
   }
}

The code above generates the following result.