ArrayBlockingQueue peek() 方法在 Java 中
ArrayBlockingQueue 類的 peek() 方法返回此佇列的頭部,如果該佇列為空則返回 null。
語法如下。
public E peek()
要使用 ArrayBlockingQueue 類,你需要匯入下列包。
import java.util.concurrent.ArrayBlockingQueue;
以下是如何在 Java ArrayBlockingQueue 類中實現 peek() 方法的示例。
示例
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.peek());
}
}輸出
ArrayBlockingQueue = [200, 310, 400, 450, 500, 550, 700] Head of the queue = 200
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP