Answers to Self-Review Exercises

17.1

a) functional interfaces.

b) parallelize.

c) internal.

d) BinaryOperator<T>.

e) Predicate<T>.

f) lambda expression.

g) lazy.

h) forEach.

i) Capturing.

j) short circuit.

k) key, value.

17.2

a) True.

b) False. Terminal operations are eager—they perform the requested operation when they are called.

c) False. When summing the elements, the identity value is 0 and when getting the product of the elements the identity value is 1.

d) True.

e) False. Stream method flatMap receives a Function that maps an object into a stream.

f) False. Should say: “...does not override them, ...” instead of “overrides them.”

17.3

a) value -> System.out.printf("%d ", value)

b) String::toUpperCase

c) () -> "Welcome to lambdas!"

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.