class ProductTitle {
private Long productId;
private String productName
private String sellerName
private Long categoryId;
private Long titleId;
private int status;
private String title;
private Long titlePrice;
}
class Aggregate {
productId;
productName;
sellerName;
categoryId;
List<TitleInfo> titles;
}
class TitleInfo {
titleId;
status;
title;
}
SampleData:
productId:1, productname: "product1", sellerName: "seller1",categoryId:2, titleId:25, status:1, title:title1
productId:1, productname: "product1", sellerName: "seller1",categoryId:2, titleId:23, status:1, title:title2
productId:1, productname: "product1", sellerName: "seller1",categoryId:2, titleId:45, status:1, title:title3
productId:2, productname: "product2", sellerName: "seller2",categoryId:5, titleId:67, status:0, title:title4
productId:2, productname: "product2", sellerName: "seller2",categoryId:5, titleId:11, status:1, title:title5
productId:3, productname: "product3", sellerName: "seller3",categoryId:9, titleId:10, status:1, title:title6
productId:6, productname: "product4", sellerName: "seller4",categoryId:7, titleId:36, status:1, title:title7
我有产品名称列表,比如sampledata。列表中的某些项重复了sellername、productname、categoryid和productid。我需要像这样输出 List<Aggregate> list
. 如何用stream得到这个结果。
对不起我的英语
1条答案
按热度按时间atmip9wb1#
我先用
groupingBy
接近mapping
值的收集器,然后map
结果Map到所需对象。对于样本数据,它产生: