Need Help ?
Have a Question ?

(Solved): Create A Separate Implementation With Interfaces For The Lambda Expressions. Below Is The Code. Impo ...

Create a separate implementation with interfaces for the lambda expressions. Below is the code.

import java.util.ArrayList;

import java.util.Arrays;

import java.util.List;

import java.util.Map;

import java.util.TreeMap;

public class lab3 {

public void runExercises() {

System.out.println("Running exercise 1 solution...");

exercise1();

System.out.println("Running exercise 2 solution...");

exercise2();

System.out.println("Running exercise 3 solution...");

exercise3();

System.out.println("Running exercise 4 solution...");

exercise4();

} private void exercise1() {

List list = Arrays.asList("alpha", "bravo", "charlie", "delta", "echo", "foxtrot");

String result = list.stream().map(s -> Character.toString(s.charAt(0))).reduce("", (a, b) -> a + b);

System.out.println(result);

} private void exercise2() {

List list = new ArrayList<>(Arrays.asList("alpha", "bravo", "charlie", "delta", "echo", "foxtrot"));

list.removeIf(s -> s.length() % 2 == 0);

list.forEach(System.out::println);

} private void exercise3() {

List list = new ArrayList<>(Arrays.asList("alpha", "bravo", "charlie", "delta", "echo", "foxtrot"));

list.replaceAll(s -> s.toUpperCase());

list.forEach(System.out::println);

} private void exercise4() {

Map map = new TreeMap<>();

map.put("c", 3);

map.put("b", 2);

map.put("a", 1);

StringBuilder builder = new StringBuilder();

map.forEach((key, value) -> builder.append(key + value));

System.out.println(builder.toString());

} public static void main(String[] args) {

lab3 lab = new lab3();

lab.runExercises(); }

}

This code already includes lambda expression, you just need to implement this code with interface

Expert Answer


importjava.util.ArrayList; importjava.util.Arrays; importjava.util.List; importjava.util.Map; importjava.util.TreeMap; importjava.util.function.BiConsumer; publicclasslab3{ p
We have an Answer from Expert Buy This Answer $6