java.util.PriorityQueue.size() 方法
描述
size() 方法用于返回此集合中元素的数量。
声明
以下是 java.util.PriorityQueue.size() 方法的声明。
public int size()
参数
NA
返回值
方法调用返回此集合中的元素个数
异常
NA
示例
下面的例子展示了 java.util.PriorityQueue.size() 的用法。
package com.tutorialspoint;
import java.util.*;
public class PriorityQueueDemo {
public static void main(String args[]) {
// create priority queue
PriorityQueue < Integer > prq = new PriorityQueue < Integer > ();
// insert values in the queue
for ( int i = 3; i < 10; i++ ) {
prq.add (new Integer (i)) ;
}
System.out.println("Size of the queue is: "+ prq.size());
System.out.println("Priority queue values are: "+ prq);
}
}
让我们编译并运行上面的程序,这将产生以下结果.
Size of the queue is: 7 Priority queue values are: [3, 4, 5, 6, 7, 8, 9]

