I have this data structure with some example content:
List<Set<Character>> aList = List.of(Set.of('a', 'b', 'c'), Set.of('a', 'b', 'c'), Set.of('a', 'b', 'c'), Set.of('a'), Set.of('b'));
I would like to retrieve the sum of all characters. In this example, it would be
3 + 3 + 3 + 1 + 1 = 11
I can solve this like that:
int sum = 0;
for (Set<Character> aSet : aList) {
sum += aSet.size();
}
But, I am almost certainly sure there's a smarter way of doing this with a stream. I just can't figure it out. Does anyone has an idea?