스트림 코플릿 연습문제
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Main {
public static void main(String[] args) {
List<Integer> list = Arrays.asList(1, 2, 3, 4, 5);
System.out.println(list.stream().mapToInt(n -> n).sum());
System.out.println(list.stream().mapToInt(n -> n).average().getAsDouble());
System.out.println(list.stream().filter(n -> n % 2 == 0).collect(Collectors.toList()));
System.out.println(list.stream().filter(n -> n % 2 == 0).count());
System.out.println(list.stream().map(n -> n * 2).collect(Collectors.toList()));
List<String> names = Arrays.asList("kim", "hong", "choi", "kim", "lee");
System.out.println(names.stream().distinct().sorted().collect(Collectors.toList()));
System.out.println(names.stream().filter(n -> n.startsWith("k")).sorted().collect(Collectors.toList()));
List<String> list1 = Arrays.asList("Hello");
List<String> list2 = Arrays.asList("World");
System.out.println(Stream.concat(list1.stream(), list2.stream()).collect(Collectors.toList()));
}
}