easier work with collections: default Stream.toList?

stephane.demurget at free.fr stephane.demurget at free.fr
Sat Sep 28 02:21:29 PDT 2013

hi guys,

Brian, you mentioned back in May the possibility that the EG might consider adding a small number of convenience methods/shortcuts for collecting elements:

    (can't reply as I was not subscribed at the time, sorry)

I see the API freeze deadline is approaching, and I grasp the problem of opening more API demand or the intent to guide users to using Collectors entirely instead, but is there any hope?

We have ~15 years of APIs all over the world accepting Collections and Maps, and I really think having those two:

* .toList()            -> .collect(Collections.toList())
* .groupBy(classifier) -> .collect(Collections.groupingBy(classifier))

would be a huge asset to use existing librairies smoothly, increasing readability and helping newcomers for the simplest and most common cases.

I understand static imports can increase readability a bit, and IDE support will certainly help in that area, but until now they were no real API "requiring" this way of writing (and if you're not, it's really verbose). I'm confident having these shortcuts with javadoc to gently point users to collectors would be really more helpful and expected.

I personally do not think .toSet() is worth it though.


More information about the lambda-dev mailing list