IDEA-195573 groupingBy test

This commit is contained in:
Tagir Valeev
2018-07-29 09:25:38 +07:00
parent 9d96fb9a63
commit 0ee4ea1fad
2 changed files with 14 additions and 0 deletions

View File

@@ -48,4 +48,12 @@ public class Main {
return result;
}));
}
void sample4(List<String> people) {
Map<Integer, List<String>> result = new HashMap<>();
for (String person : people) {
result.computeIfAbsent(person.length(), k -> new ArrayList<>()).add(person);
}
Map<Integer, List<String>> map = Collections.unmodifiableMap(result);
}
}

View File

@@ -30,4 +30,10 @@ public class Main {
Collectors.collectingAndThen(Collectors.<String, List<String>>toCollection(LinkedList::new),
list -> Stream.concat(list.stream(), list.stream()).collect(Collectors.toList())));
}
void sample4(List<String> people) {
Map<Integer, List<String>> map = people.stream().collect(
Collectors.collectingAndThen(Collectors.groupingBy(String::length),
m -> Collections.unmodifiableMap(m)));
}
}