1@Testpublic void supplierWithOptional(){
2 Supplier<Double> doubleSupplier = () -> Math.random();
3 Optional<Double> optionalDouble = Optional.empty();
4 System.out.println(optionalDouble.orElseGet(doubleSupplier));}
1@Testpublic void whenNamesPresentUseBothConsumer(){
2 List<String> cities = Arrays.asList("Sydney", "Dhaka", "New York", "London");
3 Consumer<List<String>> upperCaseConsumer = list -> {
4 for(int i=0; i< list.size(); i++){
5 list.set(i, list.get(i).toUpperCase());
6 }
7 };
8 Consumer<List<String>> printConsumer = list -> list.stream().forEach(System.out::println);
9 upperCaseConsumer.andThen(printConsumer).accept(cities);}
1@Testpublic void whenNamesPresentUseBothConsumer(){
2 List<String> cities = Arrays.asList("Sydney", "Dhaka", "New York", "London");
3 Consumer<List<String>> upperCaseConsumer = list -> {
4 for(int i=0; i< list.size(); i++){
5 list.set(i, list.get(i).toUpperCase());
6 }
7 };
8 Consumer<List<String>> printConsumer = list -> list.stream().forEach(System.out::println);
9 upperCaseConsumer.andThen(printConsumer).accept(cities);}