Close

Java 8 Streams - DoubleStream.findFirst Examples

Java 8 Streams Java Java API 


Interface:

java.util.stream.DoubleStream

java.lang.AutoCloseableAutoCloseablejava.util.stream.BaseStreamBaseStreamjava.util.stream.DoubleStreamDoubleStreamLogicBig

Method:

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.


Examples


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);
}
}

Output

1.0




See Also