IntStream toArray() 方法在 Java 中
toArray() 方法返回一个包含此数据流元素的数组。
使用 IntStream 类 of() 方法设置数据流中的元素。
IntStream stream = IntStream.of(20, 40, 60, 70, 100, 120, 140);
现在,使用 toArray() 方法,用此数据流的元素显示一个数组。
int[] myArr = stream.toArray();
以下是语法。
int[] toArray()
以下是实现 IntStream toArray() 方法在 Java 中的示例。
示例
import java.util.*;
import java.util.stream.IntStream;
public class Demo {
public static void main(String[] args) {
IntStream stream = IntStream.of(20, 40, 60, 70, 100, 120, 140);
int[] myArr = stream.toArray();
System.out.println(Arrays.toString(myArr));
}
}输出
[20, 40, 60, 70, 100, 120, 140]
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP