🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.collect returns an empty list
  2. B.The stream restarts from the beginning
  3. C.IllegalStateException: the stream has already been used
  4. 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 →