Java 中的 DoubleStream 空()带示例

原文:https://www . geesforgeks . org/double stream-empty-Java-examples/

DoubleStream empty() 是 java.util.stream.DoubleStream 中的一个方法,这个方法返回一个空的顺序 DoubleStream。 语法:

static DoubleStream empty()

Where, DoubleStream is a sequence of primitive double-valued
elements and the function returns an empty sequential stream.

例 1 :

// Java code for DoubleStream empty()
import java.util.*;
import java.util.stream.DoubleStream;

class GFG {

    // Driver code
    public static void main(String[] args)
    {
        // creating an empty DoubleStream, a sequence of
        // primitive double-valued elements
        DoubleStream stream = DoubleStream.empty();

        // Displaying an empty sequential stream
        System.out.println(stream.count());
    }
}

Output:

0

例 2 :

// Java code for DoubleStream empty()
import java.util.*;
import java.util.stream.DoubleStream;

class GFG {

    // Driver code
    public static void main(String[] args)
    {

        // creating an empty DoubleStream, a sequence of
        // primitive double-valued elements
        DoubleStream stream = DoubleStream.empty();

        // Displaying an empty sequential stream
        System.out.println(Arrays.toString(stream.toArray()));
    }
}

Output:

[]