Advertisement
desislava_topuzakova

03. Custom Min Function

Jan 25th, 2022
960
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package FunctionalProgramming_Exercise;
  2.  
  3. import java.util.Arrays;
  4. import java.util.Collections;
  5. import java.util.List;
  6. import java.util.Scanner;
  7. import java.util.function.Consumer;
  8. import java.util.function.Function;
  9. import java.util.stream.Collectors;
  10.  
  11. public class CustomMinFunction_03 {
  12.     public static void main(String[] args) {
  13.         Scanner scanner = new Scanner(System.in);
  14.         //Function<приема, връща> -> apply
  15.         //Consumer<приема> -> void -> accept
  16.         //Supplier<връща> -> get
  17.         //Predicate<приема> -> връща true / false -> test
  18.         //BiFunction<приема1, приема2, връща> -> apply
  19.         List<Integer> numbers = Arrays.stream(scanner.nextLine().split("\\s+")).map(Integer::parseInt).collect(Collectors.toList());
  20.         //начин 1
  21.         //приема лист -> връща цяло число (минимумът)  -> Function
  22.         /*Function<List<Integer>, Integer> getMinNumber = list -> Collections.min(list);
  23.         System.out.println(getMinNumber.apply(numbers));*/
  24.  
  25.  
  26.         //начин 2
  27.         //приема лист -> отпечатва цяло число (минумумът) -> Consumer
  28.         Consumer<List<Integer>> printMinNumber = list -> System.out.println(Collections.min(list));
  29.         printMinNumber.accept(numbers);
  30.        
  31.         //начин 3
  32.         //System.out.println(Collections.min(numbers));
  33.     }
  34. }
  35.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement