anyMatchis a terminal operation, so you cannot use it in combination with collect.
You can apply two filters:
List<Item> filtered =
items.stream()
.filter(Item::isBig)
.filter(i -> i.getPosts().stream().anyMatch(Post::isEnabled))
.collect(Collectors.toList());
or combine them into one filter:
List<Item> filtered =
items.stream()
.filter(i -> i.isBig() && i.getPosts().stream().anyMatch(Post::isEnabled))
.collect(Collectors.toList());
source
share