Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ...
- import javafx.util.Pair;
- ...
- Pair[] testPairs = {
- new Pair<>("apple", "James"),
- new Pair<>("banana", "John"),
- new Pair<>("grapes", "Tom"),
- new Pair<>("apple", "Jenkins"),
- new Pair<>("banana", "Edward"),
- new Pair<>("grapes", "Pierre")
- };
- Map<String, List<String>> result1 = Arrays.stream(testPairs)...;
- Map<String, String> result2 = Arrays.stream(testPairs)...;
- Map<String, List<String>> result1 = Arrays.stream(testPairs)
- .collect(Collectors.groupingBy(Pair::getS,
- Collectors.mapping(Pair::getT, Collectors.toList())));
- Map<String, String> result2 = Arrays.stream(testPairs)
- .collect(Collectors.toMap(Pair::getS, Pair::getT, (v1, v2) -> v1));
- Map<String, List<String>> result1 = Arrays.stream(testPairs).collect(Collectors
- .groupingBy(p -> (String) p.getS(),
- Collectors.mapping(p -> (String) p.getT(), Collectors.toList())));
- Map<String, String> result2 = Arrays.stream(testPairs)
- .collect(Collectors.toMap(p -> (String) p.getS(), p -> (String) p.getT(), (v1, v2) -> v1));
Add Comment
Please, Sign In to add comment