Hi Henno
You have two questions here: one about why filter (and other intermediate stream operations) weren't added directly to collections, and one about the
collect method. You and Jason have the answer to the first one about right; although it wouldn't actually be a combinatorial explosion of methods on
Collection or
Iterable, it certainly would be a lot of methods! The
Java 8 designers were very keen to create an API that would be easy to use, and cluttering a collections interface with stream operations would have been very confusing. An you need to consider that not only collections are involved; streams can be generated by a variety of means, so the same methods would have had to appear in a variety of places. It really wouldn't have made sense!
As for
collect, I think it's helpful because it emphasises that you need a
Collector to dump the contents of a stream into a collection. The
Collector API is one of the best things about streams, and IMO the confusion that would be created by hiding it with specialised collector methods added to
Stream would be a high price to pay in order to save a single method call.
Regards
Maurice