现有数据:
{a,3}
{a,5}
{b,7}
想得到
{a:[{a,3},{a,5}]}
{b,7}
代码:
List<Student> stu = ****;
Map<String, List<Student>> map = stu.stream().collect(Collectors.groupingBy(e -> e.getName()));
版权声明:本文为capricornce原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。
现有数据:
{a,3}
{a,5}
{b,7}
想得到
{a:[{a,3},{a,5}]}
{b,7}
代码:
List<Student> stu = ****;
Map<String, List<Student>> map = stu.stream().collect(Collectors.groupingBy(e -> e.getName()));