Java: List转Map 1234567// 定义实体类. record Student(String id,String name,int age){ } // 方法. List<Student> students= new ArrayList<>(1); Map<String, Student> studentIdToStudent = students.stream().collect(Collectors.toMap(Student::id, Function.identity()));