Practice Lambdas

Practice Lambdas#

Question #1: Write a lambda expression that is the same as the following method? Look for a generic functional interface that could be fulfilled by the method. Then, demonstrate how you would invoke the lambda expression.

public void printMe(String msg) {
    System.out.println(msg);
}

Question #2: Write a function named getSum that returns a Function<String, Integer> that will return the Integer value of the numeric value provided in the String plus 100. Write a second function named getSumN that will do the same thing, but return the sum of the number value provided in the String plus the value of n passed into getSumN. Lastly, show how you might invoke the code you wrote.

Question #3: Write a method consumeAll that will accept a List of integers and a Consumer<Integer> argument. Invoke the consumer behavior on every value found in the list.

Bonus: Question #4: This question requires that you know a bit about Swing. Write a simple dialog that has two buttons on it. When you click one button, “Hello” will be printed in the console. When you click the second button, the text of the Button will be printed to the console.

For this question, you do not need to write the whole program.