why combiner function is not executed in java-8 stream reduce operation?

Viewed 1169

I am trying to understand how the reduce method in streams work.

Stream.of(1,2,3,4,5,6,7).reduce(new ArrayList<>(),
(List<Integer> l, Integer a) -> {l.add(a);return l;},
(List<Integer> l1, List<Integer> l2) -> {
System.out.println("l1 is" + l1 + "l2 is " + l2);
l1.addAll(l2);
return l1;
}).forEach(System.out::println);

The line System.out.println("l1 is" + l1 + "l2 is " + l2) never gets printed. I can understand what is happening in (List<Integer> l, Integer a) -> {l.add(a);return l;}
Can some one please explain why it is not printed ? The java docs say function for combining two values, which must be compatible with the accumulator function

Thanks, Amar

2 Answers
Related