List<Student> list = new List();
// mock Data
// Collectors.toMap(key, value);
Map<String, String> nameMap = list.stream().Collect(Collectors.toMap(Student::getId, Student::getName));
java.steam().Collect(Collectors.toMap()) 用法
最新推荐文章于 2024-02-02 11:34:44 发布
该代码示例展示了如何在Java中从List<Student>集合通过StreamAPI和Collectors的toMap方法转换为Map<String,String>,将学生的ID作为键,姓名作为值。
1万+





