3 ms·
In your own code you should always use one of collection classes, usually Iterable, Collection or List, depending on which features you need. Stream usually is
by vbezhenar 4y ago
In your own code you should always use one of collection classes, usually Iterable, Collection or List, depending on which features you need.
Stream usually is not used other than for call chains. Like list.stream().map(...).toList();
I write Java for many years and I can't really say that this was source of pain for me. I agree that streams could be implemented with better ergonomics, but Java designers wanted to provide us means to use parallel computations with one extra word, so here we are. I've yet to find a place where I'd want to use that.
I used collection classes in Java 1.4 and I'm using them in Java 19 and I don't think that anything changed in that regard. Collections are the same.
- mcv 4y ago> In your own code you should always use one of collection classes, usually Iterable, Collection or List, depending on which features you need. Yes, but every library I use requires or returns a different one. > list.stream().map(...).toList() But why not list.map(...)?
- kaeruct 4y agoIn this specific case I think it is because stream operations can be implemented lazily - they only run once you call toList()