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


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


IntStream sequential()返回顺序的IntStream。它可能会返回自身,这是因为流已经是顺序的,或者是因为基础流状态已被修改为顺序的。 IntStream sequential()是中间操作。在Stream实例上调用中间操作,并在完成处理后将中间实例作为输出提供。

用法:

IntStream sequential()

Where, IntStream is a sequence of primitive
int-valued element.

示例1:


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

示例2:

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


相关用法


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