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.
[ 0 ] Comments