遍历List之后,对每条数据再进行三级联动,怎么实现
1个回答
2017-11-06
展开全部
List<Product> productList = Arrays.asList(
new Product("type1", "desc1", "brand1", "model1"),
new Product("type2", "desc2", "brand2", "model2"),
new Product("type3", "desc3", "brand3", "model3"),
new Product("type3", "desc5", "brand3", "model5"),
new Product("type4", "desc4", "brand4", "model4")
);
Map<String, Map<String,String>> productsMap =
productList.stream()
.collect(Collectors.groupingBy(Product::getType, // 第一层种类映射
Collectors.groupingBy(Product::getBrand, // 第二层品牌映射
Collectors.mapping(Product::getModel, Collectors.joining(", ")))));
new Product("type1", "desc1", "brand1", "model1"),
new Product("type2", "desc2", "brand2", "model2"),
new Product("type3", "desc3", "brand3", "model3"),
new Product("type3", "desc5", "brand3", "model5"),
new Product("type4", "desc4", "brand4", "model4")
);
Map<String, Map<String,String>> productsMap =
productList.stream()
.collect(Collectors.groupingBy(Product::getType, // 第一层种类映射
Collectors.groupingBy(Product::getBrand, // 第二层品牌映射
Collectors.mapping(Product::getModel, Collectors.joining(", ")))));
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询