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:
// Java program to demonstrate // OptionalDouble.stream() method import java.util.OptionalDouble; import java.util.stream.DoubleStream; public class GFG { public static void main(String[] args) { // create a OptionalDouble OptionalDouble opDouble = OptionalDouble.of(. 3203 ); // get value as stream DoubleStream out = opDouble.stream(); // print value System.out.print( "Value: " ); out.forEach(System.out::print); } } |
Output:
Program 2:
// Java program to demonstrate // OptionalDouble.stream() method import java.util.OptionalDouble; import java.util.stream.DoubleStream; public class GFG { public static void main(String[] args) { // create a empty OptionalDouble OptionalDouble opDouble = OptionalDouble.empty(); // get value as stream DoubleStream out = opDouble.stream(); // print value System.out.print( "length of Double Stream: " + out.count()); } } |
Output:
References: https://docs.oracle.com/javase/10/docs/api/java/util/OptionalDouble.html#empty()
Recommended Posts:
- OptionalDouble hashCode() method in Java with examples
- OptionalDouble isPresent() method in Java with examples
- OptionalDouble orElseGet() method in Java with examples
- OptionalDouble ifPresentOrElse() method in Java with examples
- OptionalDouble of(double) method in Java with examples
- OptionalDouble toString() method in Java with examples
- OptionalDouble empty() method in Java with examples
- OptionalDouble orElseThrow() method in Java with examples
- OptionalDouble getAsDouble() method in Java with examples
- OptionalDouble equals() method in Java with examples
- OptionalDouble orElse(double) method in Java with examples
- OptionalDouble ifPresent(DoubleConsumer) method in Java with examples
- OptionalDouble orElseThrow(Supplier) method in Java with examples
- Stream.max() method in Java with Examples
- Stream min() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.