Java 中的 ConcurrentLinkedQueue
Java 中的 ConcurrentLinkedQueue 类用于实现一个队列,该队列使用一个并发链表。此类实现了 Collection 接口和 AbstractCollection 类。它属于 Java 集合框架的一部分。
以下给出了一个展示此类的程序 −
示例
import java.util.concurrent.*;
public class Demo {
public static void main(String[] args) {
ConcurrentLinkedQueue<String> clQueue = new ConcurrentLinkedQueue<String>();
clQueue.add("Amy");
clQueue.add("John");
clQueue.add("May");
clQueue.add("Harry");
clQueue.add("Anne");
System.out.println("The elements in ConcurrentLinkedQueue are: " + clQueue);
}
}以上程序的输出如下 −
输出
The elements in ConcurrentLinkedQueue are: [Amy, John, May, Harry, Anne]
现在让我们来理解一下以上程序。
创建一个 ConcurrentLinkedQueue,然后向其中添加元素。最后,对它进行显示。以下给出了一个展示此类的代码段 −
ConcurrentLinkedQueue<String> clQueue = new ConcurrentLinkedQueue<String>();
clQueue.add("Amy");
clQueue.add("John");
clQueue.add("May");
clQueue.add("Harry");
clQueue.add("Anne");
System.out.println("The elements in ConcurrentLinkedQueue are: " + clQueue);
广告
数据结构
网络
关系型数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
JavaScript
PHP