Difficulty: Beginner
Estimated Time: 10 minutes

// This is your Editor pane. Write your Java here and // use the command line to execute commands //Write a program to print odd, even and numbers greater than 5 //using Consumer functional Interface in addition to Predicate interface. //Hint: Method accept(T t) to be used to print the numbers. import java.util.; import java.util.function.; public class App {

public static void main(String[] args) {

List<Integer> lst = Arrays.asList(1,3,5,3,2,12,56,3,2);
  
  System.out.println("Odd List");
    printOddList(lst,l->System.out.println(l), l-> l%2!=0 );
  System.out.println("Even List");
    printEvenList(lst,l->System.out.println(l), l-> l%2==0 );
  System.out.println("Elements Greater Than 5 List");
    printGreaterThan5List(lst,l->System.out.println(l), l-> l>5 );
  

} private static void printOddList(List lst, Consumer c, Predicate p){ lst.forEach(l->{if(p.test(l)) c.accept(l);}); }

private static void printEvenList(List lst, Consumer c, Predicate p){ lst.forEach(l->{if(p.test(l)) c.accept(l);}); }

private static void printGreaterThan5List(List lst, Consumer c, Predicate p){ lst.forEach(l->{if(p.test(l)) c.accept(l);}); }

}

Don’t stop now! The next scenario will only take about 10 minutes to complete.

Functional Interface Hands On 2

App