← Quiz: Java Streams in Depth: all 10 questions
Quiz: Java Streams in Depth · Question 9 of 10
You call count() on a stream and then call collect() on the same stream. What happens?
You call count() on a stream and then call collect() on the same stream. What happens?
- A.collect returns an empty list
- B.The stream restarts from the beginning
- C.IllegalStateException: the stream has already been used
- D.It works because count does not consume elements
Answer & explanation
Correct answer: IllegalStateException: the stream has already been used
A stream can have only one terminal operation. Create a new stream from the source instead.
Can you get the rest right without peeking?
Take the timed Quiz: Java Streams in Depth quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →