📜  Java中的DoubleStream顺序()

📅  最后修改于: 2022-05-13 01:55:39.806000             🧑  作者: Mango

Java中的DoubleStream顺序()

DoubleStream sequence()返回一个连续的 DoubleStream。它可能会返回自己,因为流已经是顺序的,或者因为基础流状态被修改为顺序。

DoubleStreamsequential() 是一个中间操作。在 Stream 实例上调用中间操作,在它们完成处理后,它们给出一个 Stream 实例作为输出。

句法 :

DoubleStream sequential()

Where, DoubleStream is a sequence of primitive
double-valued element.

返回值:一个顺序的 DoubleStream。
示例 1: DoubleStream 顺序()返回一个顺序的 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 上的 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