The collect operation

Some of the usages of the collect() operation are very simple and recommended for any beginner, while other cases can be complex and inaccessible even for a seasoned programmer. Together with the operations discussed already, the most popular cases of collect() we present in this section are more than enough for all the needs a beginner may have. Add the operations of numeric streams we are going to present in the Numeric stream interfaces section, and the covered material may easily be all a mainstream programmer will need for the foreseeable future.

As we have mentioned already, the collect operation is very flexible, and allows us to customize the stream processing. It has two forms:

  • R collect(Collector<T, A, R> ...

Get Introduction to Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.