August 2014
Intermediate to advanced
424 pages
13h 50m
English
One of the biggest limitations of a Java 8 stream is that you can operate on it only once and get only one result while processing it. Indeed, if you try to traverse a stream for a second time, the only thing you can achieve is an exception like this:
java.lang.IllegalStateException: stream has already been operated upon or closed
Despite this, there are situations where you’d like to get several results when processing a single stream. For instance, you may want to parse a log file in a stream, as we did in section 5.7.3, but gather multiple statistics in a single step. Or, keeping with the menu data model used to explain Stream’s features in chapters 4–6, you may want to retrieve ...