Map<String, Object> 如何使用groupingBy得到

  • Post author:
  • Post category:其他



最近网上搜 gruping by, 几乎大家都是整理的Map<String, List<Object>> 一定要带个List分组的 后面自己查找项目代码找到了一个写法

Map<String, Student> objectMap = StudentList.stream()
                .collect(Collectors.groupingBy(Student::getName, Collectors.reducing(new Student(), (o1, o2) -> o2)));
或者:
Map<String, StudentStream> objectMap2 = StudentList.stream()
                .collect(Collectors.toMap(StudentStream::getName, e -> e, (o1, o2) -> o2))

// 待补充 Stream流 常用方法合集



版权声明:本文为weixin_40689677原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。