Core Java 11: Lambdas & Streams Flashcards

(4 cards)

1
Q

What is a lambda?

A

a lambda is an anonymous function; arrow function (in JS); it contains a parenthesized set of parameters, an arrow ->, then a body (either a single expression or a block of code)

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

Why are lambdas useful?

A

they can be passed into a method designed to accept them as a parameter, such as ArrayList.forEach( (n) -> { System.out.println(n); } );

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

What are streams?

A

Java streams (introduced in Java 8) represent a pipeline through which data will flow and methods to operate on data; streams consist of a stream source, one or more intermediate operations, and a terminal operation.

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

Why are streams useful?

A

Streams are useful because they allow you to process data in a more efficient way; you can perform operations such as filter, map, or reduce w/o for loops.

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