博客目录
- 1.单字段分组
- 2.多字段分组
- 3.每个店铺的价格等级
- 4.多字段分组
1.单字段分组
Map<String, List<TaskRecordDO>> collect1 = list.stream().collect(Collectors.groupingBy(TaskRecordDO::getOutNodeKey));
@Test
public void test13() {
//所有价格等级的店铺列表
Map<Integer, List<Property>> priceMap = properties.stream()
.collect(Collectors.groupingBy(Property::getPriceLevel));
System.out.println(JSON.toJSONString(priceMap));
}
2.多字段分组
//多字段
Map<String, List<DayStoreSkuSizeInvSalDTO>> financialYearWeekInfo = sizeIndex.stream().collect(Collectors.groupingBy(p -> p.getFinancialYear() + ":" + p.getFinancialWeek()));
3.每个店铺的价格等级
每个店铺的价格等级:
@Test
public void test12() {
//获取每个店铺的价格等级
Map<String, Integer> map = properties.stream()
.collect(Collectors.toMap(Property::getName, Property::getPriceLevel));
System.out.println(JSON.toJSONString(map));
}
4.多字段分组
分组:
Map<Integer, Map<Integer, List<StoreSalCalendarDTO>>> groupByYearMonth = results.stream().collect(Collectors.groupingBy(StoreSalCalendarDTO::getFinancialYear, Collectors.groupingBy(StoreSalCalendarDTO::getFinancialYearMonth)));
遍历:
Map<Integer, Map<Integer, List<StoreSalCalendarDTO>>> groupByYearMonth = new HashMap<>();
if (Objects.nonNull(groupByYearMonth)) {
groupByYearMonth.forEach((year, yearValue) -> {
if (Objects.nonNull(yearValue)) {
yearValue.forEach((month, monthValue) -> {
});
}
});
}
觉得有用的话点个赞 👍🏻
呗。
❤️❤️❤️本人水平有限,如有纰漏,欢迎各位大佬评论批评指正!😄😄😄
💘💘💘如果觉得这篇文对你有帮助的话,也请给个点赞、收藏下吧,非常感谢!👍 👍 👍
🔥🔥🔥Stay Hungry Stay Foolish 道阻且长,行则将至,让我们一起加油吧!🌙🌙🌙