ArrayBlockingQueue poll() 方法
Java 中 ArrayBlockingQueue 类的方法 poll() 从此队列中检索并移除头,如果此队列为空,则返回 null。
语法如下
E poll()
使用 ArrayBlockingQueue 类,需要导入以下包
import java.util.concurrent.ArrayBlockingQueue;
以下是 Java ArrayBlockingQueue 类的 poll() 方法的实现示例
示例
import java.util.concurrent.ArrayBlockingQueue;
public class Demo {
public static void main(String[] args) throws InterruptedException {
ArrayBlockingQueue<Integer> q = new ArrayBlockingQueue<Integer>(10);
q.add(200);
q.add(310);
q.add(400);
q.add(450);
q.add(500);
q.add(550);
q.add(700);
System.out.println("ArrayBlockingQueue = " + q);
System.out.println("Head of the queue = "+q.poll());
System.out.println("Head of the queue now = "+q.poll());
System.out.println("ArrayBlockingQueue = " + q);
}
}输出
ArrayBlockingQueue = [200, 310, 400, 450, 500, 550, 700] Head of the queue = 200 Head of the queue now = 310 ArrayBlockingQueue = [400, 450, 500, 550, 700]
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
安卓
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP