I have this class.
class Assignment {
private Integer index;
private List<Quantity> quantities;
}
Then, I have a list of objects from that class.
List<Assigment> assignments = new ArrayList<>();
Is there a way to create a Map that contains the index from Assignment and the List<Quantity> as values?
This is what I have tried so far.
assignments.stream().collect(groupingBy(Assignment::getIndex));
But this gives me a Map<Integer, List<Assignment>> and I want a Map<Integer, List<Quantity>>.
I have tried using forEach method - and it workes - but I'm sure there must be a way to do it in one liner - or at least using only collect and groupingBy methods