我正在尝试使用流按国籍对我的对象进行分组并将其打印出来。
但它说:“无法解析方法'println”
class Person {
private String name;
private int age;
private String nationality;
public static void groupByNationality(List<Person> people) {
people
.stream()
.collect(Collectors.groupingBy(Person::getNationality))
.forEach(System.out::println);
}
Run Code Online (Sandbox Code Playgroud)