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


Java LongStream sequential()用法及代碼示例


LongStream sequential()返回順序的LongStream。它可能會返回自身,這是因為流已經是順序的,或者是因為基礎流狀態已被修改為順序的。 LongStream sequential()是中間操作。在Stream實例上調用中間操作,並在完成處理後將中間實例作為輸出提供。

用法:

LongStream sequential()

Where, LongStream is a sequence of primitive
long-valued element.

示例1:


// Java code for LongStream sequential() 
// to return a sequential LongStream. 
import java.util.*; 
import java.util.stream.LongStream; 
  
class GFG { 
  
    // Driver code 
    public static void main(String[] args) 
    { 
        // Creating an LongStream 
        LongStream stream = LongStream.of(3L, 5L, 9L, 12L, 14L); 
  
        // Using LongStream sequential() 
        LongStream streamNew = stream.sequential(); 
  
        // Displaying sequential LongStream 
        streamNew.forEach(System.out::println); 
    } 
}
輸出:
3
5
9
12
14

示例2:

// Java code for LongStream sequential() 
// to return a sequential LongStream. 
import java.util.*; 
import java.util.stream.LongStream; 
  
class GFG { 
  
    // Driver code 
    public static void main(String[] args) 
    { 
        // Creating an LongStream of elements 
        // in range [-2, 4) 
        LongStream stream = LongStream.range(-2L, 4L); 
  
        // Using LongStream sequential() 
        LongStream streamNew = stream.sequential(); 
  
        // Displaying sequential IntStream 
        streamNew.forEach(System.out::println); 
    } 
}
輸出:
-2
-1
0
1
2
3


相關用法


注:本文由純淨天空篩選整理自Sahil_Bansall大神的英文原創作品 LongStream sequential() in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。