Java中的IntStream empty()及其示例

IntStream empty() 是java中的一种方法。util。流动IntStream。此方法返回一个空的顺序IntStream。 语法:

null
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: 创建空的长流。

// 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
© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享