0
我分组和partioning流如下:我可以通过功能分组结合分组吗?
// Partioning
Map<Boolean, List<Person>> partitioned = persons.stream().
collect(Collectors.partitioningBy(p -> p.getAge() > 20));
// Grouping
Map<String, List<Person>> grouped = persons.stream()
.collect(Collectors.groupingBy(p -> p.getCity()));
有没有一种方法,我可以结合这两种?我尝试了使用groupingBy在partioningBy中进行组合,但没有得到正确的结果。任何建议?
预期的结果是对那些名字以P开头并按年龄分组的人进行分区。 这里是人名单: 名单的人=
Arrays.asList(
new Person("Max", 18),
new Person("Peter", 23),
new Person("Pamela", 23),
new Person("David", 12),
new Person("Pam", 12));
预期结果会是什么? – Tunaki
这些陈述工作正常。 – KayV
@Tunaki进行了编辑以查看预期。 – KayV