'Java streaming options to merge the list of string on the same map object

I have use case to get the distinct value from the map. Is there any way using streams

Sample Model data set = {"Ford":{"hatchback", "sedan", "TEST"}, "Honda":{"hatchback", "sedan"}, "Toyota":{"hatchback", "sedan", "TeST2"}}

for (Entry<String, Set<String>> model: models.entrySet()) {
modelList.addAll(model.getValue()); 
}


Final List: {"hatchback", "sedan", "TEST", "TeST2"}


Solution 1:[1]

        List<String> unique=set.stream().flatMap(map->map.values().stream()).flatMap(list->list.stream()).distinct().collect(Collectors.toList());

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Chaman Jain