Java中的PriorityBlockingQueue类
Java中的PriorityBlockingQueue类具有一个具有无限功能的阻塞队列,并且基于具有相同排序规则的PriorityQueue类。PriorityBlockingQueue类是Java集合框架的一部分。
演示此的程序如下所示-
示例
import java.util.concurrent.PriorityBlockingQueue;
public class Demo {
public static void main(String[] args) {
PriorityBlockingQueue<String> pbQueue = new PriorityBlockingQueue<String>();
pbQueue.add("James");
pbQueue.add("May");
pbQueue.add("John");
pbQueue.add("Sara");
pbQueue.add("Anne");
System.out.println("The elements in PriorityBlockingQueue are: " + pbQueue);
}
}上面程序的输出如下-
输出结果
The elements in PriorityBlockingQueue are: [Anne, James, John, Sara, May]
现在让我们了解上面的程序。
创建PriorityBlockingQueue,然后将元素添加到其中。最后,元素按顺序显示。证明这一点的代码片段如下-
PriorityBlockingQueue<String> pbQueue = new PriorityBlockingQueue<String>();
pbQueue.add("James");
pbQueue.add("May");
pbQueue.add("John");
pbQueue.add("Sara");
pbQueue.add("Anne");
System.out.println("The elements in PriorityBlockingQueue are: " + pbQueue);热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短