How it works...
As we mentioned in the introduction of this recipe, the collect() method allows you to do a mutable reduction of the elements of a Stream. We call it a mutable reduction because the final result of the stream will be a mutable data structure, such as Map or List. The Stream class of the Java Concurrency API provides two versions of the collect() method.
The first one receives only one parameter that is an implementation of the Collector interface. This interface has seven methods, so you normally won't implement your own collectors. Instead of this, you will use the utility class Collectors, which has a lot of methods that return ready-to-use Collector objects for your reduce operations. In our example, we have used the following ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access