public class Record {
//组
private String group;
//code
private String code;
//数量
private Integer count;
}
List list=new ArrayList<>();
list.add(new Record("组 1","code1",2));
list.add(new Record("组 1","code2",1));
list.add(new Record("组 2","code1",1));
list.add(new Record("组 2","code3",1));
前端希望的结果展示如下,所有左边的列(组)都是另一个地方查出来的需要与现在这个集合去匹配
------ code1 code2 code3
组 1 - | 2 | 1 | 0
组 2 - | 1 | 0 | 1
合计 - | 3 | 1 | 1
现在除了 filter 再 groupby 之后 其他组里存在 code,但本组里不存在就没有完全显示,还有什么好的办法能够完整展示这个结果吗
Map collect = list.stream().filter(record -> "组 1".equals(record.getGroup()))
.collect(
Collectors.groupingBy(Record::getCode, Collectors.summingInt(Record::getCount)));
{code2=1, code1=2}
{code3=1, code1=1}