package vood; import java.util.function.BinaryOperator; import java.util.stream.Stream; public class Ahel1 { public static void main(String[] args) { String[] eesnimed = { "Juku", "Madis", "Anu", "Mati" }; String pikim=Stream.of(eesnimed).reduce("", (s1, s2) -> (s1.length() > s2.length()) ? s1 : s2); System.out.println(pikim); //Loo reduce-funktsioon, mis ühendab kõik nimed //üheks pikaks stringiks String koikKoos=Stream.of(eesnimed).reduce("", (s1, s2) -> s1+s2); System.out.println(koikKoos); Integer[] m={1, 3, 4, 5}; System.out.println(Stream.of(m).reduce(1, (a1, a2) -> a1*a2)); BinaryOperatorliida=(a1, a2) -> a1+a2; BinaryOperatorkorruta=(a1, a2) -> a1*a2; System.out.println(Stream.of(m).reduce(0, liida)); System.out.println(Stream.of(m).reduce(1, korruta)); } }