count() — counts elements. reduce() — combines elements into a single value using a custom function. Think of count() as counting apples in a basket, while reduce() as combining apples into cider — each step merges two things into one.
count():
long.reduce(0L, Long::sum, Long::sum).1long count = list.stream()2 .filter(x -> x > 10)3 .count();
reduce():
Optional<T> or T.1Optional<Integer> sum = list.stream()2 .reduce(Integer::sum);3Optional<Integer> max = list.stream()4 .reduce(Integer::max);5String concat = list.stream()6 .reduce("", String::concat);
Key difference: