Java DoubleStream sequential()
DoubleStream sequential() 返回一个连续的DoubleStream。它可能会返回自己,因为流已经是连续的,或者因为底层流的状态被修改为连续的。
DoubleStream sequential()是一个 中间操作。 中间操作是在一个Stream实例上调用的,在它们完成处理后,会给出一个Stream实例作为输出:
语法:
DoubleStream sequential()
其中,DoubleStream是一串原始的
双值元素的序列。
返回值: 一个连续的DoubleStream。
示例1: DoubleStream sequential()返回一个连续的DoubleStream。
// Java code for DoubleStream sequential()
// to return a sequential DoubleStream.
import java.util.*;
import java.util.stream.DoubleStream;
class GFG {
// Driver code
public static void main(String[] args)
{
// Creating an DoubleStream
DoubleStream stream = DoubleStream.of(3.3, 5.4, 9.2,
12.1, 14.4);
// Using DoubleStream sequential()
DoubleStream streamNew = stream.sequential();
// Displaying sequential DoubleStream
streamNew.forEach(System.out::println);
}
}
输出:
3.3
5.4
9.2
12.1
14.4
例2: DoubleStream sequential()对空DoubleStream的处理。
// Java code for DoubleStream sequential()
// on empty DoubleStream
import java.util.*;
import java.util.stream.DoubleStream;
class GFG {
// Driver code
public static void main(String[] args)
{
// Creating an empty DoubleStream
DoubleStream stream = DoubleStream.empty();
// To check if it is parallel or not
System.out.println("parallel : " + stream.isParallel());
stream = stream.parallel();
// To check if it is parallel or not
System.out.println("parallel : " + stream.isParallel());
stream = stream.sequential();
// To check if it is parallel or not
System.out.println("parallel : " + stream.isParallel());
}
}
输出:
parallel : false
parallel : true
parallel : false