Categories: Java Java Programming & Coding
Minimum using java8 stream api
package r4r.in;
public class MinimumUsingJava8StreamAPI {
public static void main(String[] args) {
//Minimum using java8 stream api
Integer[] input = { 12, 122, -11, 120, 21, 23 };
int min1 = Stream.of(input).reduce(Integer::min).get();
System.out.println("Min using Stream reduce() mrthod =" + min1);
int min2 = Stream.of(input).reduce((x, y) -> x > y ? y : x).orElse(-1);
System.out.println("Min using Stream reduce() mrthod =" + min2);
}
}