filter
메서드는 프리디케이트
를 인수로 받아서 프레디케이트와 일치하는 모든 요소를 포함하느 스트림을 반환한다.List<Dish> vegetarianMenu =
menu.stream()
.filter(Dish::isVegetarian)
.collect(toList());
http://drive.google.com/uc?export=view&id=0ByLqiEM75qEzeDBOdjkzekZKdTA
프레디케이트로 필터링
distinct
라는 메서드도 지원한다.List<Integer> numbers = Arrays.asList(1, 2 ,1, 3, 3, 2, 4);
numbers.stream().filter (i -> i % 2 == 0)
.distinct()
.forEach(System.out::println);
http://drive.google.com/uc?export=view&id=0ByLqiEM75qEzd2pqQWtKalp4Smc
고유 요소 필터링
limit(n)
메서드를 지원한다.List<Dish> dishes = menu.stream()
.filter(d -> d.getCalories() > 300)
.limit(3)
.collect(toList());
http://drive.google.com/uc?export=view&id=0ByLqiEM75qEzcXFDcHBoZUtiYTg
스트림 축소