问题说明
就是Map处理,value是个集合,取出集合中的最大值,返回还要是int类型
package com.company;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author fanzhen1@lixiang.com
* @version 1.0
* @date 2022/12/5
*/
public class test6 {
public static void main(String[] args) {
Employee employee = new Employee(15, 15, "18801171255", "man", 1, Arrays.asList(1, 2, 3));
Employee employee1 = new Employee(18, 16, "18801171255", "woman", 2, Arrays.asList(2, 3, 4));
Employee employee2 = new Employee(20, 17, "18801171255", "man", 3, Arrays.asList(3, 4, 5));
Employee employee3 = new Employee(20, 18, "18801171255", "man", 5, Arrays.asList(5, 7, 7));
List<Employee> list = new ArrayList<>();
list.add(employee);
list.add(employee1);
list.add(employee2);
list.add(employee3);
Map<Integer, Integer> map = list.stream().collect(Collectors.toMap(Employee::getAge,
item -> item.getChildren().stream().collect(Collectors.summarizingInt(children->children.intValue())).getMax()));
Set<Map.Entry<Integer, Integer>> en = map.entrySet();
for (Map.Entry<Integer, Integer> e : en) {
System.out.println(e.getKey() + ":" + e.getValue());
}
}
}