java – Java 8 stream Map to List

You should get the entrySet map and paste the entries to the calls of your binary function:


The above result is a flow of T instances.


Your additional example confirms what was discussed in the comments below: group by And sort they are by their nature terminal operations. They must be carried out in full to be able to produce even the first element of the output, so involving them as non-terminal operations they buy nothing in terms of performance / memory footprint.

It happens that Java 8 defines sorted as a non-terminal operation, however that decision could lead to a deceptive code because the operation will block until it has received all the upstream elements, and they will have to keep them all while receiving.

Leave a comment