package vood; import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Arrays; import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.List; public class Esimene { public static void main(String[] args) throws IOException{ String[] eesnimed=Stream.of("Juku", "Kati", "Madis", "Mati"). map(s -> s.toUpperCase()).filter(s->s.length()==4). toArray(String[]::new); System.out.println(Arrays.toString(eesnimed)); List nimeloetelu=Stream.of(eesnimed).map(s -> s+s). collect(Collectors.toList()); nimeloetelu.add("Juhan"); //nimeloetelu.stream().forEach(System.out::println); nimeloetelu.stream().peek(System.out::println). collect(Collectors.toList()).stream(). map(s->s+"!") .forEach(System.out::println); //Ühe käsuga tehke kolm nime vooks, eraldage neist esitähed //ning trükkige välja Files.write(Paths.get("sorditud.txt"), Files.lines(Paths.get(".", "eesnimed.txt")). sorted((s1, s2)->s1.length()-s2.length()). collect(Collectors.toList()), Charset.defaultCharset()); } }