我有带数据点的类。类的定义如下:
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分类,然后用白酒分类。
我想把List<ExciseReportDataPoint>转换成Map<String, Map <String, List<List<String>>>>。我不确定是否可以使用流和收集器。
有人接过这个吗?
发布于 2017-02-14 11:00:25
您可以将您的列表分组几次:
Map<String, Map<String, List<ExciseReportDataPoint>>> map = list.stream().collect(Collectors.groupingBy(ExciseReportDataPoint::getLiquorCategoryName, Collectors.groupingBy(ExciseReportDataPoint::getLiquorName)));https://stackoverflow.com/questions/42223171
复制相似问题