Java Reference
In-Depth Information
As you can see, in this way you can avoid creating a completely new class that implements the
Collector interface; the resulting code is more compact, even if it's also probably less readable
and certainly less reusable.
6.7. Summary
Following are the key concepts you should take away from this chapter:
collect
is a terminal operation that takes as argument various recipes (called collectors) for
accumulating the elements of a stream into a summary result.
Predefined collectors include reducing and summarizing stream elements into a single value, such as
Predefined collectors let you group elements of a stream with
groupingBy
and partition elements of a
stream with
partitioningBy
.
Collectors compose effectively to create multilevel groupings, partitions, and reductions.
You can develop your own collectors by implementing the methods defined in the
Collector
interface.
Search WWH ::
Custom Search