Challenge 3: Calling a Terminal Operation Twice on the Same Stream — Possible Solution ==================================================================== ReuseDemo.java: import java.util.List; import java.util.stream.Stream; public class ReuseDemo { public static void main(String[] args) { List names = List.of("Alice", "Bob", "Carol"); Stream s = names.stream(); s.forEach(System.out::println); // first terminal operation -- fine s.forEach(System.out::println); // second terminal operation on the SAME stream object } } Representative runtime exception: Alice Bob Carol Exception in thread "main" java.lang.IllegalStateException: stream has already been operated upon or closed at java.base/java.util.stream.AbstractPipeline.sourceStageSpliterator(...) at java.base/java.util.stream.ReferencePipeline$Head.forEach(...) at ReuseDemo.main(ReuseDemo.java:9) Explanation: The first forEach() successfully consumes the stream `s`, printing all three names. Once a terminal operation has run, that specific Stream object is considered spent -- it doesn't reset or become reusable. Calling forEach() a second time on the exact same `s` reference throws IllegalStateException, because there's no data left for it to operate on; the pipeline was already exhausted. The fix would be to call names.stream() again to get a brand new Stream instance for the second forEach(), rather than reusing `s`. WHY THIS WORKS AS AN ANSWER ------------------------------ This reproduces the exact single-use violation the chapter's warn-box describes -- two terminal operations on one stream object -- and explains the IllegalStateException in terms of the stream being "spent" after its first terminal operation, matching the chapter's own stated behavior.