OptionalDouble stream() method in Java with examples
The stream() method help us to get double value contain by OptionalDouble as DoubleStream.If a value is present, method returns a sequential DoubleStream containing only that value, otherwise returns an empty DoubleStream.
Syntax:
public DoubleStream stream()
Parameters: This method accepts nothing.
Return value: This method returns the optional value as an DoubleStream.
Below programs illustrate stream() method:
Program 1:
import java.util.OptionalDouble;
import java.util.stream.DoubleStream;
public class GFG {
public static void main(String[] args)
{
OptionalDouble opDouble
= OptionalDouble.of(. 3203 );
DoubleStream out = opDouble.stream();
System.out.print( "Value: " );
out.forEach(System.out::print);
}
}
|
Output:
Program 2:
import java.util.OptionalDouble;
import java.util.stream.DoubleStream;
public class GFG {
public static void main(String[] args)
{
OptionalDouble opDouble
= OptionalDouble.empty();
DoubleStream out = opDouble.stream();
System.out.print( "length of Double Stream: "
+ out.count());
}
}
|
Output:
References: https://docs.oracle.com/javase/10/docs/api/java/util/OptionalDouble.html#empty()
Last Updated :
28 May, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...