Is there any advantage of calling map after mapToInt, where ever required
问题 I am trying to calculate the sum of squares of values in the list. Below are three variations which all calculates the required value. I want to know which one is the most efficient. I am expecting the third one to be more efficient as auto boxing is only done once. // sum of squares int sum = list.stream().map(x -> x * x).reduce((x, y) -> x + y).get(); System.out.println("sum of squares: " + sum); sum = list.stream().mapToInt(x -> x * x).sum(); System.out.println("sum of squares: " + sum);