Java Reference
In-Depth Information
Figure 5-4. Accumulator
The
combine
method is an analogue of the third method of our
reduce
operation. If we have
two containers, then we need to be able to merge them together. Again, we've already imple-
mented this in a previous refactor step, so we just use the
StringCombiner.merge
method
(
Example 5-28
)
.
Example 5-28. A combiner merges together two containers
public
public
BinaryOperator
<
StringCombiner
>
combiner
() {
return
return
StringCombiner:
:
merge
;
}
During the collect operation, our container objects are pairwise merged using the defined
combiner
until we have only one container at the end (
Figure 5-5
).