DoubleStream findAny()
returns
an OptionalDouble describing some element of the stream,
or an empty OptionalDouble if the stream is empty.
This is a short-circuiting terminal operation.
findAny
has the following syntax.
OptionalDouble findAny()
The following example shows how to use findAny
.
import java.util.OptionalDouble; import java.util.stream.DoubleStream; /* www. j a va 2s . co m*/ public class Main { public static void main(String[] args) { DoubleStream b = DoubleStream.of(1.1,2.2,3.3,4.4,5.5); OptionalDouble d = b.findAny(); if(d.isPresent()){ System.out.println(d.getAsDouble()); }else{ System.out.println("no data"); } } }
The code above generates the following result.