[문제]
정수 리스트에서 10 이상인 숫자만 필터링한 후, 각 숫자를 2배로 변환하여 출력하세요.
[데이터]
[5, 15, 3, 20, 8, 25, 12]
[요구사항]
- filter()와 map() 메서드 순서대로 사용
- 필터링된 숫자들을 2배로 변환
[소스]
import java.util.Arrays;
import java.util.List;
public class FilterMapCombine {
public static void main(String[] args) {
List<Integer> numbers = Arrays.asList(5, 15, 3, 20, 8, 25, 12);
System.out.println("원본 숫자: " + numbers);
System.out.println("\n10 이상인 숫자를 2배로 변환:");
// filter로 조건에 맞는 요소 필터링 후, map으로 변환
numbers.stream()
.filter(n -> n >= 10) // 10 이상만 통과
.map(n -> n * 2) // 2배로 변환
.forEach(System.out::println);
}
}
다음검색