How does the reduce() method work in Java 8?
问题 I try to understand how does the reduce() method work in java-8. For example I have this code: public class App { public static void main(String[] args) { String[] arr = {"lorem", "ipsum", "sit", "amet"}; List<String> strs = Arrays.asList(arr); int ijk = strs.stream().reduce(0, (a, b) -> { System.out.println("Accumulator, a = " + a + ", b = " + b); return a + b.length(); }, (a, b) -> { System.out.println("Combiner"); return a * b; }); System.out.println(ijk); } } And the output is this: