Java
-
자바 스트림(stream)을 이용한 데이터 가공 (map, filter, sorted / collect/foreach)Java 2022. 11. 11. 15:27
Stream? 컬렉션의 여러 인터페이스(List, Set, Map 등)마다 데이터 핸들링을 위한 메서드가 다 다르다. 하지만 이것을 stream으로 변환해줌으로써 통일된 메서드로 데이터를 다룰 수 있다. 더불어 람다 함수형식을 사용할 수 있어 간결하고 깔끔한 코드로 요소를 처리할 수 있다. Stream으로 변환된 배열의 원소를 가공할 때는 map, filter, sorted 등이 있다. map : 요소들을 특정 조건에 해당하는 값으로 변환해줄 때 요소들을 대, 소문자 변형 등 작업을 하고 싶을 때 사용한다. list.stream().map(s->s.toUpperCase()); list.stream().map(String::toUpperCase); filter : 요소들을 조건에 따라 걸러내고 싶을 때 길..