Last active
August 29, 2015 14:01
-
-
Save Oregu/7696491814560e7c94ea to your computer and use it in GitHub Desktop.
Reduce 2D collection in Java 8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Map<String, List<Field>> fieldmap = new HashMap<>(); | |
fieldmap.put("f1", Arrays.asList(new Field("f_str"), new Field("f_abc"))); | |
fieldmap.put("f2", Arrays.asList(new Field("f_int"))); | |
// This is the best I came up with | |
List<String> names = fieldmap.values().stream().collect( | |
ArrayList<String>::new, | |
(l, fs) -> l.addAll(fs.stream().map(Field::getName).collect(toList())), | |
ArrayList<String>::addAll); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment