I have java POJO with following fields
class Product{
private String productName;
private String productCode;
private String price;
private String productId;
private String country;
private List<Comments> comments;
}
class Comments {
private String productCode;
private String languageCode;
private String comment;
}
When I retrieve data from the database. I get the data in the following format.
productName, productCode, price, productId, country, languageCode , comment
iPhone , 1XBA22 , 1000 , 134 , USA , EN , comment in English
iPhone , 1XBA22 , 1000 , 134 , USA , CN , comment in Chinese
laptop , 1234 , 2000 , 145 , UK , EN , comment in English
laptop , 1234 , 2000 , 145 , UK , CN , comment in Chinese
laptop , 1234 , 2000 , 145 , UK , FR , comment in French
This result from db is stored in following data structure.
class ProductWithComments{
private String productName;
private String productCode;
private String price;
private String productId;
private String country;
private String comment;
private String languageCode;
}
now, as you can see, the product with comments has duplicate products. because each product has comments in many languages, using Java Streams API, how can I convert the above list of data into List into List.
meaning, I group by Product and each product has many Comments. So basically grouping by needs to happen using many columns (productName , productCode, price, productId, country)
then all the Comments for one Group should be listed in List<Comments>
. Thanks in advance for any guide on this.
Regarding the comment that this question is similar to other questions in Stackoverflow, here is my explanation. My question is about multiple grouping fileds. The URL you have provided is grouped by one field. When group by is done using one field, it is straightforward