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