DEV Community

Discussion on: The joy of streams

Collapse
 
pawelsalawa profile image
Pawel Salawa • Edited

I love Java's streams, but still there is one thing which I hate about them. Verbosity where it's really not necessary and I see just one case where it's not necessary - for collectors. Every time we want to terminate a stream by getting collection from it, we had to do this ugly "collect(Collectors.toSomthieng())". I know, I know. It enables us to provide our custom collectors, but I don't see why Stream class does not have simple method "toList()" and "toSet()". These are the most common cases! Have a look: "stream.collect(Collectors.toList())" vs "stream.toList()". I didn't do any research, but I bet toList and toSet operations are like 80% of cases. Why not make this simpler? We still could use collect() for more customization, but lack of toList() and toSet() in the Stream is such a pain! Having such methods comes directly from intuition. These are the first which people look like when they learn Stream. It's not lost, since we have default methods and future Java versions may introduce these methods. I hope so. Maybe there's already such proposal and I just couldn't find it?

Collapse
 
bertilmuth profile image
Bertil Muth

I understand your pain :-) As far as I know, the vavr library tries to solve that problem.