#387 Reusing a Stream After count

Companies:
Itone
Themes:
JavaStreams & LambdasCode Review

Will this code run?

List<Integer> list = new ArrayList<>();

// ...

Stream<Integer> s = list.stream().filter(i -> i % 2 == 0);

long count = s.count();

if (count > 100) {
    List<Integer> even = s.collect(Collectors.toList());
    // ...
}

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in