📜  Java中的 IntStream empty() 示例

📅  最后修改于: 2022-05-13 01:54:30.436000             🧑  作者: Mango

Java中的 IntStream empty() 示例

IntStream empty()是Java.util.stream.IntStream 中的一个方法。此方法返回一个空的顺序 IntStream。
句法 :

static  Stream 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