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