Stream API Flashcards

1
Q
  1. What is the difference between an intermediate operation and a terminal operation?
  2. When is a stream traversed?
A
  1. An intermediate operation returns a new stream. A terminal operation consumes the stream
  2. When a terminal operation is executed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Do the operations of a stream modify its source?

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the 3 components of a stream pipeline?

A
  • Source
  • 0 or more intermediate operations
  • 1 terminal operation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the 2 most common ways of creating a stream?

A
  1. collection.stream()
  2. Arrays.stream(...)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How can a stream be used to produce a new collection?

A

stream.collect(Collectors...)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly