I have a class "First" which contains reference to Class "Second" as list. I am trying to achieve below block in Java 8 way by using Stream (or) flap Map (or) groupingBy
foreach(First a: listOfFirst){
for (Second b: a.getSecondDetails()) {
inputMap.put(b, a);
}
}
I tried below simplified way
listOfFirst.stream()
.flatMap(p -> p.getSecondDetails().stream())
.collect(Collectors.toMap(p -> p, q -> q));
I am missing something here, please help me out