Check out example codes for "java 8 function supplier consumer". It will help you in understanding the concepts better.

Code Example 1

@Testpublic void whenNamesPresentUseBothConsumer(){    
  List<String> cities = Arrays.asList("Sydney", "Dhaka", "New York", "London");    
  Consumer<List<String>> upperCaseConsumer = list -> {
    for(int i=0; i< list.size(); i++){            
      list.set(i, list.get(i).toUpperCase());        
    }    
  };    
  Consumer<List<String>> printConsumer = list -> list.stream().forEach(System.out::println);    
  upperCaseConsumer.andThen(printConsumer).accept(cities);}

Code Example 2

@Testpublic void whenNamesPresentUseBothConsumer(){    
  List<String> cities = Arrays.asList("Sydney", "Dhaka", "New York", "London");   
  Consumer<List<String>> upperCaseConsumer = list -> {        
    for(int i=0; i< list.size(); i++){            
      list.set(i, list.get(i).toUpperCase());        
    }    
  };    
  Consumer<List<String>> printConsumer = list -> list.stream().forEach(System.out::println);    
  upperCaseConsumer.andThen(printConsumer).accept(cities);}

Code Example 3

@Testpublic void supplierWithOptional(){    
  Supplier<Double> doubleSupplier = () -> Math.random();   
  Optional<Double> optionalDouble = Optional.empty();    
  System.out.println(optionalDouble.orElseGet(doubleSupplier));}

Code Example 4

@Testpublic void supplierWithOptional(){    Supplier<Double> doubleSupplier = () -> Math.random();    Optional<Double> optionalDouble = Optional.empty();    System.out.println(optionalDouble.orElseGet(doubleSupplier));}

Learn ReactJs, React Native from akashmittal.com