Java Streams .max() and .min() lag in performance?
问题 Consider Below 2 examples. 1 With Streams myList.stream().map(this::getInt).max(Integer::compareTo); 2 Old way int max = Integer.MIN_VALUE; for (MyItem item : myList) { max = Math.max(max, getInt(item)); } Above getInt method accepts a MyItem argument and returns an int result. Here, #2 gives me a much lower latency compared to #1. Does anyone have an idea why or anything going wrong for me? 回答1: myList.stream().mapToInt(this::getInt).max() Try mapping to an IntStream. An IntStream works with