Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package asd;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
- import java.util.function.BinaryOperator;
- import java.util.function.Function;
- //FunctionalInterface
- interface Math{
- public int add(int x, int y);
- }
- interface Sort{
- public int reversed(String x, String y);
- }
- public class Main {
- public Main() {
- List<String> names = new ArrayList<>();
- names.add("Clavianus Juneardo");
- names.add("Vincent Colin");
- names.add("Gregory James");
- names.add("Jonathan Ramlie");
- names.add("Billy Purnama");
- // Functional Interface
- Math math = (int x, int y) -> x + y;
- System.out.println(math.add(2, 2));
- Sort sort = (String x, String y) -> y.compareTo(x);
- Collections.reverse(names);
- //Lambda Expression
- Function<Integer, Integer> pow = x -> x*x;
- System.out.println(pow.apply(2));
- BinaryOperator<Integer> add = (x,y) -> x + y;
- System.out.println(add.apply(2,2));
- //parallel function
- names.stream()
- .sorted( (x,y) -> sort.reversed(y,x) )
- .filter( name -> !name.equals("Clavianus Juneardo") )
- .forEach( System.out::println );
- }
- public static void main(String[] args) { new Main(); }
- }
Add Comment
Please, Sign In to add comment