当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java DoubleStream sequential()用法及代码示例


DoubleStream sequential()返回顺序的DoubleStream。它可能会返回自身,这是因为流已经是顺序的,或者是因为基础流状态已被修改为顺序的。

DoubleStream sequential()是中间操作。在Stream实例上调用中间操作,并在完成处理后将中间实例作为输出提供。

用法:


DoubleStream sequential()

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

返回值:顺序的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上的DoubleStream sequential()。

// 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


相关用法


注:本文由纯净天空筛选整理自Sahil_Bansall大神的英文原创作品 DoubleStream sequential() in Java。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。