我有数据点课。类定义如下:
public class ExciseReportDataPoint {
private String liquorCategoryName;
private String liquorName;
private String nozzleName;
private String bottleExciseNumber;
private int fixedPegSize;
private double costPerPeg;
private int bottleSize;
private int consumedVolumeInMl;
private int volumeInBottleInMl;
private boolean isBottleEmpty;
private int totalNoOfPegsPoured;
private double totalSaleValue;
// Getters and setters for all
}
我从我的API获得List<ExciseReportDataPoint>
。我想显示表格报告,其中行必须先用LiquorCategory然后用Liquor进行分类。
我想将List<ExciseReportDataPoint>
转换为Map<String, Map <String, List<List<String>>>>
。我不确定是否可以使用 stream 和收藏家
有没有人接受这个?
答案 0 :(得分:0)
您可以多次对列表进行分组:
Map<String, Map<String, List<ExciseReportDataPoint>>> map = list.stream().collect(Collectors.groupingBy(ExciseReportDataPoint::getLiquorCategoryName, Collectors.groupingBy(ExciseReportDataPoint::getLiquorName)));