IntStream min() example
Description
IntStream min()
returns an OptionalInt
describing the minimum element of this stream, or an empty optional if this stream is empty.
Syntax
min
has the following syntax.
OptionalInt min()
Example
The following example shows how to use min
.
import java.util.OptionalInt;
import java.util.stream.IntStream;
// ww w . j a v a 2 s. co m
public class Main {
public static void main(String[] args) {
IntStream i = IntStream.of(6,5,7,1, 2, 3, 3);
OptionalInt d = i.min();
if(d.isPresent()){
System.out.println(d.getAsInt());
}else{
System.out.println("no value");
}
}
}
The code above generates the following result.