Using a stream twice
QuizMediumJava only
A stream is a pipeline over a collection, and count() ends it and returns the number of elements. What happens on the second call?
Stream<Integer> st = List.of(3, 1, 2).stream();
st.count();
st.count();- It throws IllegalStateException: "stream has already been operated upon or closed"
- It returns 3 again
- It returns 0
- It does not compile
This question is part of Pro+
Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.