Calculate size of priority queue in java.� 

Calculate size of priority queue in java.� 


Posted in : Core Java Posted on : December 9, 2010 at 5:18 PM Comments : [ 0 ]

In this example, you will see how to calculate the size of priority Queue in java.

Calculate size of priority queue in java. 

In this example, you will see how to calculate the size of priority queue. The size of priority queue means total number of element present in queue. The size() method of PriorityQueue class returns size of queue.

Code:

SizeOfPriorityQueue.java

import java.util.PriorityQueue;

public class SizeOfPriorityQueue {
	public static void main(String[] args) {
		PriorityQueue obPriorQueue = new PriorityQueue();
		obPriorQueue.add("B");
		obPriorQueue.add("A");
		obPriorQueue.add("C");
		obPriorQueue.add("D");
		obPriorQueue.add("E");
		System.out.println("Size of priority queue : ");
		System.out.println(obPriorQueue.size());
	}
}
Output:
Size of priority queue :
5

Download this code.
Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics