Question: Write a lambda or method reference for each of the following tasks: a) Write a lambda that can that can be passed to a method

Write a lambda or method reference for each of the following tasks:

a) Write a lambda that can that can be passed to a method with an IntConsumer parameter. The lambda should display its argument followed by a space.

b) Write a method reference that can be used in place of the following lambda:

(String s) -> {return s.toUpperCase();}

c) Write a no-argument lambda that implicitly returns the String "Welcome to lambdas!".

d) Write a method reference for Math method sqrt.

e) Create a one-parameter lambda that returns the cube of its argument.

Step by Step Solution

3.19 Rating (166 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

a Value Systemoutprintfd ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Java How to Program Early Objects Questions!