Java 8 Streams Java Java API
java.util.stream.DoubleStream
OptionalDouble findFirst()
This terminal-short-circuiting operation returns an OptionalDouble describing the first element of this stream, or an empty OptionalDouble if the stream is empty. If the stream has no encounter order, then any element may be returned.
OptionalDouble
package com.logicbig.example.doublestream;import java.util.stream.DoubleStream;public class FindFirstExample { public static void main(String... args) { DoubleStream ds = DoubleStream.of(1.0, 1.2, 2.0, 2.4, 3.0); double v = ds.findFirst() .orElseThrow(IllegalArgumentException::new); System.out.println(v); }}
1.0