好吧,您没有说明确切的过滤条件,但是假设您希望按给定年份过滤元素:
List<Name> names = projects.stream() .filter(p -> p.getYear() == someYear) // keep only projects of a // given year .flatMap(p -> p.getNames().stream()) // get a Stream of all the // Names of all Projects // that passed the filter .collect(Collectors.toList()); // collect to a List



