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 : 创建空的输入流。
// 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
版权属于:月萌API www.moonapi.com,转载请注明出处