15.4.1_Using Streams Flashcards

1
Q

📝️What is a java.util.stream?

A

A java.util.stream is a sequence of data.

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

📝️What is a stream pipeline?

A

-> A stream pipeline consists of the operations that run on a stream to produce a result.

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

📝️ Which analogy would you use to explain stream pipeline Flow?

A

Factory - Foreman

  • > Java serves as the foreman when working with stream pipelines.
  • > Think of declaring the stream as giving instructions to the foreman.
  • > The foreman sets up the stations and tells the workers what their duties will be.
  • > The workers do not start until the foreman tells them to begin.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

📝️ What are the three parts to a stream pipeline?

A

Source | Intermediate | Terminal
📝️Source: Where the stream comes from
📝️Intermediate operations: Transforms the stream into another one.
There can be as few or as many intermediate operations as you’d like. Since streams use
lazy evaluation, the intermediate operations do not run until the terminal operation runs.
📝️Terminal operation: Actually produces a result. Since streams can be used only once,
the stream is no longer valid after a terminal operation completes.

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

📝️ What are the Stream static methods?

A

empty | of+Nullable | generate | iterate** | concat | builder

⚠️ Finite Streams -> empty | of + Nullable
⚠️ Infinite Streams -> generate | iterate **

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

📝️ Intermediate vs Terminal operations?

A

Intermdiate Terminal
Required part of a useful pipeline? ❌ ✅
Can exist multiple times in a pipeline? ✅ ❌
Return type is a stream type? ✅ ❌
Executed upon method call? ❌ ✅
Stream valid after call? ✅ ❌

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

📝️ What are the Terminal operations?

A
count
max | min
find{Any | First}
{all | any | none}Match
forEach | reduce | collect
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

📝️ What are the Stream Terminal Operations [PITFALLS]?

A

🤯️⚠️📣️ allMatch - If the stream is empty true is returned and the predicate is not evaluated

🤯️⚠️📣️ forEach - It’s the only terminal operation with a return type of void.

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

📝️ What are the Intermediate Operations?

A

filter | limit | sorted | peek
map | flatMap
distinct | skip

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