I have something like the below :
public class MyClass {
private Long stackId
private Long questionId
}
A collection of say 100, where the stackid could be duplicate with different questionIds. Its a one to many relationship between stackId and questionId
Is there a streamy, java 8 way to convert to the below strcuture :
public class MyOtherClass {
private Long stackId
private Collection<Long> questionIds
}
Which would be a collection of 25, with each instance having a nested collection of 4 questionIds.
Input :
[{1,100},{1,101},{1,102},{1,103},{2,200},{2,201},{2,202},{1,203}]
Output
[{1, [100,101,102,103]},{2,[200,201,202,203]}]
Map<Long, Collection<Long>>first, then convert the entries of that map to (the second kind of)MyClassinstances.