If it is Java8 or later, it seems that you should use flatMap
.
Map<UserId, List<User>> userMap;
List<User> users = userMap.values()
.stream()
.flatMap(Collection::stream) // List<User> -> Stream<User>Conversion to
.collect(Collectors.toList());
map ()
is a method that extracts the elements of Collectioin and performs conversion.
flatMap ()
is a method that takes out the elements of Collection and converts them to Stream.