Posts

Java 8 stream max() function argument type Comparator vs Comparable

Image
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box; } 12 3 I wrote some simple code like below. This class works fine without any errors. public class Test { public static void main(String args) { List<Integer> intList = IntStream.of(1,2,3,4,5,6,7,8,9,10).boxed().collect(Collectors.toList()); int value = intList.stream().max(Integer::compareTo).get(); //int value = intList.stream().max(<Comparator<? super T> comparator type should pass here>).get(); System.out.println("value :"+value); } } As the code comment shows the max() method should pass an argument of type Comparator<? super Integer> . ...