Stream.max(Integer::max) : Unexpected result [duplicate]
This question already has an answer here: Java 8 stream's .min() and .max(): why does this compile? 5 answers I'm studying for 1z0-809 : Java SE 8 Programmer II using Enthuware's mocktests. Encountering this question. List<Integer> ls = Arrays.asList(3,4,6,9,2,5,7); System.out.println(ls.stream().reduce(Integer.MIN_VALUE, (a, b)->a>b?a:b)); //1 System.out.println(ls.stream().max(Integer::max).get()); //2 System.out.println(ls.stream().max(Integer::compare).get()); //3 System.out.println(ls.stream().max((a, b)->a>b?a:b)); //4 Which of the above statements will print 9? Answer is 1 and 3 But