ArrayBlockingQueue toArray() 方法在 Java 中
ArrayBlockingQueue 类中的 toArray() 方法返回包含此队列中所有元素的数组。
语法如下
Object[] toArray()
要使用 ArrayBlockingQueue 类,你需要导入以下软件包
import java.util.concurrent.ArrayBlockingQueue;
以下是实现 Java ArrayBlockingQueue 类的 toArray() 方法的一个示例
示例
import java.util.ArrayList;
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);
Object[] arr = q.toArray();
System.out.println("Array...");
for (Object ob : arr) {
System.out.println(ob);
}
}
}输出
ArrayBlockingQueue = [200, 310, 400, 450, 500, 550, 700] Array... 200 310 400 450 500 550 700
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP