I have a map currently which is Map<String, Map<String, List<String>>>
I want to do an operation on each item in each nested list.
I can do it with lots of nested for-loops:
(EDIT - Updating parameters of performOperation function)
final Set<ResultType> resultSet = new HashSet<>();
for(Map.Entry<String, Map<String, List<String>>> topKeyEntry : inputNestedMap.entrySet()) {
for (Map.Entry<String, List<String>> innerKeyEntry : topKeyEntry.getValue().entrySet()) {
for (String listItem : innerKeyEntry.getValue()) {
resultSet.add(performOperation(listItem, topKeyEntry.getKey(), innerKeyEntry.getKey()));
}
}
}
How do I do it with streams?
I tried it with nesting stream and apply map() and eventually calling the operation in the innermost map, but that results in an error saying there is a return missing.
I tried to flatten the entry list with flatMap() but could not get through.
performOperationon each item in the nested lusts and add it to a result set. that currently thats what I am doing with nest for's, but want to do with streams to be cleaner