void clear()
描述 (Description)
clear()方法用于从此优先级队列中删除所有元素。 此调用返回后,队列将为空。
声明 (Declaration)
以下是java.util.PriorityQueue.clear()方法的声明。
public void clear()
参数 (Parameters)
NA
返回值 (Return Value)
NA
异常 (Exception)
NA
例子 (Example)
以下示例显示了java.util.PriorityQueue.clear()的用法
package com.iowiki;
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 = 0; i < 10; i++ ) {
prq.add (new Integer (i)) ;
}
System.out.println("Priority queue values are: " + prq);
// clear the queue
prq.clear();
System.out.println("Priority queue values after clear: " + prq);
}
}
让我们编译并运行上面的程序,这将产生以下结果。
Priority queue values are: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Priority queue values after clear: []