DoubleStream findFirst() returns an OptionalDouble (a container object which may or may not contain a non-null value) describing the first element of this stream, or an empty OptionalDouble if the stream is empty.
- OptionalDouble : A container object which may or may not contain a non-null value.
Return Value : The function returns an OptionalDouble describing the first element of this stream, or an empty OptionalDouble if the stream is empty.
Note : findFirst() is a terminal-short-circuiting operation of Stream interface. This method returns any first element satisfying the intermediate operations.
Example 1 : findFirst() method on Double Stream.
Note : If the stream has no encounter order, then any element may be returned.
Example 2 : findFirst() method to return the first element which is divisible by 4.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.