先对list集合数据进行分组,然后对分组后的map转换成list使用
1.通过构造函数改变类型
List<sVo> sVoList=
list.stream()
.collect(Collectors.groupingBy(tVo::getType))
.entrySet().stream()
.map(e -> new sVo(e.getKey(), e.getValue().size()))
.collect(Collectors.toList());
2.通过赋值return
List<sVo> sVoList=
list.stream()
.collect(Collectors.groupingBy(tVo::getType))
.entrySet().stream()
.map(e ->{
sVo temp = new sVo();
temp.setSum(e.getValue().size());
temp.setTypeName(e.getKey());
return temp;
}).collect(Collectors.toList());