I have a list of lists like that:
List<List<Wrapper>> listOfLists = new ArrayList<>();
class Wrapper {
private int value = 0;
public int getValue() {
return value;
}
}
so it looks like that:
[
[Wrapper(3), Wrapper(4), Wrapper(5)],
[Wrapper(1), Wrapper(2), Wrapper(9)],
[Wrapper(4), Wrapper(10), Wrapper(11)],
]
Is there a concise way to flatten this list of lists like below using lambda functions in Java 8:
(per column): [Wrapper(8), Wrapper(16), Wrapper(25)]
(per row): [Wrapper(12), Wrapper(12), Wrapper(25)]
potentially it could work with different sizes of internal lists:
[
[Wrapper(3), Wrapper(5)],
[Wrapper(1), Wrapper(2), Wrapper(9)],
[Wrapper(4)],
]
this would result to:
(per column): [Wrapper(8), Wrapper(7), Wrapper(9)]
(per row): [Wrapper(8), Wrapper(11), Wrapper(4)]
it seems way more complicated than: Turn a List of Lists into a List Using Lambdas and 3 ways to flatten a list of lists. Is there a reason to prefer one of them?
and what I initially did is similar to although for lists: https://stackoverflow.com/a/36878011/986160
Thanks!