Stream API Flashcards
7 cards from real 1Z0-819 practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 Stream API flashcards as text
Which collector creates an unmodifiable list in Java 10+?
Answer: Collectors.toUnmodifiableList()
Collectors.toUnmodifiableList() was introduced in Java 10 and returns an unmodifiable List.
What happens when you call a terminal operation on a stream that has already been consumed?
Answer: It throws IllegalStateException
Streams can only be consumed once; calling a second terminal operation throws IllegalStateException: stream has already been operated upon or closed.
Which of the following correctly creates a parallel stream from a List?
Answer: Both A and B
Both list.stream().parallel() and list.parallelStream() produce an equivalent parallel stream.
What does flatMap() do differently from map()?
Answer: flatMap() flattens a stream of streams into a single stream
flatMap() applies a function that returns a Stream for each element and then flattens all resulting streams into one.
What is the return type of Stream.collect(Collectors.toMap(k, v))?
Answer: Map
Collectors.toMap() returns a Map (the concrete type is unspecified but typically HashMap).
Which statement correctly describes a short-circuit terminal operation?
Answer: It terminates stream processing early when the result can be determined
Short-circuit terminal operations like findFirst(), anyMatch(), and allMatch() can stop processing as soon as a definitive result is found.
What does Stream.of(1, 2, 3).mapToInt(Integer::intValue).boxed() return?
Answer: Stream
boxed() on an IntStream converts each int to Integer and returns a Stream.