I am trying to use map to map a set of keys into a Map of String to Set of Integer. Ideally I want to get all the value sets and collect them into a single set.
Lets say I have:
Map<String, List<Integer>> keyValueMap = new HashMap<>();
Set<String> keys = new HashSet<>();
Set<String> result = new HashSet<>();
I have tried:
result.addAll(keys.stream().map(key -> keyValueMap.get(key)).collect(Collectors.toSet());
This nets me an error saying addAll() is not applicable for the type Set>. I have tried replacing map() with flatMap() but I can't seem to get the syntax right if that is the solution.
What is the correct syntax to make this work?
Thanks!