This may be a perversion, but I want to combine the results of the internal thread for the thread at a higher level.
For example, we have some complex data mapping:
Map<String, List<Map<String, Object>>> dataMap
and I need to collect all the objects in a list. While I'm doing it like this:
Set<Object> segmentIds = new HashSet<>();
dataMap.values().forEach(maps -> maps.forEach(map -> segmentIds.add(map.get("object"))));
But it is not beautiful. But I can’t understand how to transfer data from the inner loop to the outer loop to collect them at the end.
Can this be done without any external objects?
source
share