Java中的LongStream顺序()
LongStreamsequential()返回一个连续的 LongStream。它可能会返回自己,因为流已经是顺序的,或者因为底层流状态被修改为顺序。 LongStreamsequential() 是一个中间操作。在 Stream 实例上调用中间操作,在它们完成处理后,它们给出一个 Stream 实例作为输出。
句法 :
LongStream sequential()
Where, LongStream is a sequence of primitive
long-valued element.
示例 1:
// Java code for LongStream sequential()
// to return a sequential LongStream.
import java.util.*;
import java.util.stream.LongStream;
class GFG {
// Driver code
public static void main(String[] args)
{
// Creating an LongStream
LongStream stream = LongStream.of(3L, 5L, 9L, 12L, 14L);
// Using LongStream sequential()
LongStream streamNew = stream.sequential();
// Displaying sequential LongStream
streamNew.forEach(System.out::println);
}
}
输出:
3
5
9
12
14
示例 2:
// Java code for LongStream sequential()
// to return a sequential LongStream.
import java.util.*;
import java.util.stream.LongStream;
class GFG {
// Driver code
public static void main(String[] args)
{
// Creating an LongStream of elements
// in range [-2, 4)
LongStream stream = LongStream.range(-2L, 4L);
// Using LongStream sequential()
LongStream streamNew = stream.sequential();
// Displaying sequential IntStream
streamNew.forEach(System.out::println);
}
}
输出:
-2
-1
0
1
2
3