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