boolean remove(Object o)
描述 (Description)
remove(Object o)方法用于从此队列中删除指定元素的单个实例(如果存在)。
声明 (Declaration)
以下是java.util.PriorityQueue.remove()方法的声明。
public boolean remove(Object o)
参数 (Parameters)
o - 要从此队列中删除的元素。
返回值 (Return Value)
如果此队列因调用而更改,则方法调用将返回“true”。
异常 (Exception)
NA
例子 (Example)
以下示例显示了java.util.PriorityQueue.remove()的用法
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 = 3; i < 10; i++ ) {
prq.add (new Integer (i)) ;
}
System.out.println("Initial priority queue values are: "+ prq);
// remove 7 from the queue
boolean isremoved = prq.remove(7);
System.out.println("Return value after remove: "+ isremoved);
System.out.println("Priority queue values after remove: "+ prq);
}
}
让我们编译并运行上面的程序,这将产生以下结果。
Initial priority queue values are: [3, 4, 5, 6, 7, 8, 9]
Return value after remove: true
Priority queue values after remove: [3, 4, 5, 6, 9, 8]