Stream API Flashcards
1
Q
- What is the difference between an intermediate operation and a terminal operation?
- When is a stream traversed?
A
- An intermediate operation returns a new stream. A terminal operation consumes the stream
- When a terminal operation is executed
2
Q
Do the operations of a stream modify its source?
A
No
3
Q
What are the 3 components of a stream pipeline?
A
- Source
- 0 or more intermediate operations
- 1 terminal operation
4
Q
What are the 2 most common ways of creating a stream?
A
collection.stream()
Arrays.stream(...)
5
Q
What is Collectors and what does it do?
A
Collectors is an implementation of Collector and it provides many static methods to perform reduction operations
6
Q
Is it a good practice to modify the source of an active stream?
A
Absolutely not. Refrain from modifying the source of an active stream
7
Q
How can a stream be used to produce a new collection?
A
stream.collect(Collectors...)