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