You can just have
List<String> result = map.values().stream().flatMap(List::stream).collect(Collectors.toList());
This retrieves the values of the map with values() then flat maps each list into a Stream formed by its elements and collects the result into a list.
Another alternative, without flat mapping each list, and thus may be more performant, is to collect directly the Stream<List<String>>
(returned by values().stream()
) by calling addAll
on each accumulated result.
List<String> result = map.values().stream().collect(ArrayList::new, List::addAll, List::addAll);