當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。