JAVA

Java8 Stream filter, map, flatMap 샘플

Rust Choi 2019. 11. 22. 17:38

stream 에서 filter, map, flatmap 을 사용한 샘플 코드입니다

String[][] arrays = new String[][]{ {"a1", "a2"}, {"b1", "b2"}, {"c1", "c2", "c3"} };
Stream<String[]> stream6 = Arrays.stream(arrays);
Stream<String> stream7 = stream6.flatMap(s -> Arrays.stream(s));
stream7.filter(s-> s.startsWith("a"))
        .map(String::toUpperCase).forEach(System.out::println);

결과

A1

A2