size(): This method is available in java.util.PriorityQueue class of Java.
Syntax:
int java.util.PriorityQueue.size()
This method returns the number of elements in this collection.
Note: If this collection contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.
Parameters: NA
Returns: the number of elements in this collection.
Exceptions: NA
Approach
Java
import java.util.PriorityQueue;public class PriorityQueuesize {public static void main(String[] args) {PriorityQueue<Integer> priorityQueue =new PriorityQueue<Integer>();priorityQueue.add(12);priorityQueue.add(5);priorityQueue.add(10);priorityQueue.add(2);System.out.println(priorityQueue.size());}}
Output:
4
No comments:
Post a Comment