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


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


IntStream empty()是java.util.stream.IntStream中的方法。此方法返回空的顺序IntStream。
用法:

static <T> Stream<T> empty()

Where, T is the type of stream elements,
and the function returns an empty sequential stream.

示例1:创建空的IntStream。

// Java code for IntStream empty() 
import java.util.*; 
import java.util.stream.IntStream; 
  
class GFG { 
      
    // Driver code 
    public static void main(String[] args) { 
      
    // creating an empty IntStream, a sequence of  
    // primitive int-valued elements 
    IntStream stream = IntStream.empty(); 
      
    // Displaying an empty sequential stream 
    System.out.println(stream.count()); 
} 
}

输出:


0

示例2:创建空的LongStream。

// Java code for LongStream empty() method 
import java.util.*; 
import java.util.stream.LongStream; 
  
class GFG { 
      
    // Driver code 
    public static void main(String[] args) { 
      
    // creating an empty LongStream, a sequence of 
    // primitive long-valued elements 
    LongStream stream = LongStream.empty(); 
      
    // Displaying an empty sequential stream 
    System.out.println(stream.count()); 
} 
}

输出:

0


相关用法


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