I am having 2 lists of Dto objects, both are retireved from different BQ query.
Example: BQ result list 1 : List bq1 = {[name:”abc”, country: “ca”, nbr:334],[name:”dcc”, country: “ca”, nbr:222], [name:”aop”, country: “in”, nbr:234]}
BQ rsult list 2: List bq2 = {[color:a, nbr:334],[color:n, nbr:334], [color:e, nbr:234]}
I want to combine both list based on nbr value and create new list.
expected: List result = {[name:”aop”, country: “in”, nbr:234, color: e], [name:”abc”, country: “ca”, nbr:334, color: a], [name:”abc”, country: “ca”, nbr:334, color: n]}
But when thee are more than one records with same nbr , i am getting only one set of values repeated.
Existing result: List result = {[name:”aop”, country: “in”, nbr:234, color: e], [name:”abc”, country: “ca”, nbr:334, color: a], [name:”abc”, country: “ca”, nbr:334, color: a]}
I am using Java8, Any help would be appreciated. Thanks
`List<Data> resultList = new ArrayList<>();
Map<String, List<Data>> mapByItemNumber = bqList.stream()
.collect(Collectors.groupingBy(BQItemData::getNbr));
for (Dataitem : bq3List) {
if (mapByItemNumber.containsKey(item.getNbr())) {
for (Datai : mapByItemNumber.get(item.getNbr())) {
i.setColor(item.getColor());
resultList.add(i);
}
}
}`