I have two lists and I have to create a map from them. One, I am iterating in for loop and second I wanted to go threw by a stream and than collect to map, but I have no idea how to use Collectors.toMap in that specific case. Is it possible?
I already made a solution, but not using stream, however I am very curious is it possible to do it and if yes, how to do it?
public void findMatch(List<ObjectA> objectAList, List<ObjectB> objectBList) {
Map<ObjectB, ObjectA> objectBObjectAMap = new HashMap<>();
for (ObjectB objectB : objectBList) {
if (isNull(objectB.getHandoverTime())) {
objectBObjectAMap.putAll(
objectAList
.stream()
.filter(objectA -> {
ObjectC objectC = objectB.getObjectC();
return objectA.getNumber().equals(objectC.getNumber())
&& objectA.getQuality().equals(objectC.getQuality());
})
.collect(Collectors.toMap(???)));
}
}
}