Skip to content

Instantly share code, notes, and snippets.

@tag1216
Created December 18, 2014 06:13
Show Gist options
  • Save tag1216/994043491d9708492071 to your computer and use it in GitHub Desktop.
Save tag1216/994043491d9708492071 to your computer and use it in GitHub Desktop.
Collectors.groupingBy()でList<? extends String>をcollect
Map<Integer, List<String>> list4 = Stream.of("a", "b")
.collect(Collectors.groupingBy(
String::length,
Collectors.toCollection(() -> new ArrayList<String>())
));
Map<Integer, List<? extends String>> list5 = Stream.of("a", "b")
.collect(Collectors.groupingBy(
String::length,
Collector.of(
() -> new ArrayList<String>(),
(list, x) -> list.add(x),
(x, y) -> { x.addAll(y); return x; },
list -> (List<? extends String>) list
)
));
Map<Integer, List<? extends String>> list6 = Stream.of("a", "b")
.collect(Collectors.groupingBy(
String::length,
Collectors.collectingAndThen(
Collectors.toList(),
l -> (List<? extends String>) l
)
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment