asLongStream()
IntStream类的方法返回一个LongStream,它由转换为long的该流的元素组成。
语法如下
LongStream asLongStream()
创建一个IntStream并在Stream中添加一些元素
IntStream intStream = IntStream.of(30, 40, 60, 70, 90, 110, 140, 150);
现在,使用asLongStream()
方法将其转换为long
LongStream longStream = intStream.asLongStream();
以下是asLongStream()
在Java中实现IntStream方法的示例
import java.util.*; import java.util.stream.IntStream; import java.util.stream.LongStream; public class Demo { public static void main(String[] args) { IntStream intStream = IntStream.of(30, 40, 60, 70, 90, 110, 140, 150); LongStream longStream = intStream.asLongStream(); longStream.forEach(System.out::println); } }
输出结果
30 40 60 70 90 110 140 150