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


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。