Java中的 IntStream asLongStream()
IntStream asLongStream()返回由该流的元素组成的LongStream ,转换为 long。这是一个中间操作。在 Stream 实例上调用中间操作,在它们完成处理后,它们给出一个 Stream 实例作为输出。
句法 :
LongStream asLongStream()
Where, LongStream is a sequence of
primitive long-valued element.
返回值: IntStream asLongStream() 返回一个由该流的元素组成的 LongStream,转换为 long。
示例 1:
// Java code for LongStream asLongStream()
// to return a LongStream consisting of
// the elements of this stream
import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
class GFG {
// Driver code
public static void main(String[] args)
{
// Creating an IntStream
IntStream stream = IntStream.of(3, 5, 9, 12, 14);
// Using LongStream asLongStream()
LongStream stream1 = stream.asLongStream();
// Displaying LongStream consisting of
// the elements of this stream
stream1.forEach(System.out::println);
}
}
输出 :
3
5
9
12
14
示例 2:
// Java code for LongStream asLongStream()
// to return a LongStream consisting of
// the elements of this stream
import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
class GFG {
// Driver code
public static void main(String[] args)
{
// Creating an IntStream and using asLongStream()
LongStream stream = IntStream.range(3, 8).asLongStream();
// Displaying LongStream consisting of
// the elements of this stream
stream.forEach(System.out::println);
}
}
输出 :
3
4
5
6
7