What happens when the Java code Stream<Integer> s = Stream.of(1); s.count(); s.count(); is run?
Correct answer A. The second count throws an IllegalStateException
Explanation
A stream may be operated on only once. The first terminal operation consumes it, so linking or consuming it again throws IllegalStateException at run time. Streams are not containers of data but single-use pipelines over a source. The usual remedy is to create a fresh stream from the source each time one is needed.
Answer checked How we write and check questions
Discussion