Conditionally add an operation to a Java 8 stream
问题 I'm wondering if I can add an operation to a stream, based off of some sort of condition set outside of the stream. For example, I want to add a limit operation to the stream if my limit variable is not equal to -1 . My code currently looks like this, but I have yet to see other examples of streams being used this way, where a Stream object is reassigned to the result of an intermediate operation applied on itself: // Do some stream stuff stream = stream.filter(e -> e.getTimestamp() < max); /