Java通过stream将list转换成map
List<Employee> department = new LinkedList<>(
Arrays.asList(
new Employee("张三", 12, "2012-11-12"),
new Employee("李四", 9, "2018-06-01"),
new Employee("王五", 11.5, "2019-06-01"),
new Employee("赵六", 11.2, "2018-11-02")
)
);
Map<Integer, Employee> map = department.stream().collect(Collectors.toMap(Employee::getId, (employee -> employee)));
map.forEach((id, employee)->{
System.out.println(id+", "+employee.getName());
});