Guest User

Untitled

a guest
Sep 21st, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. ...
  2. import javafx.util.Pair;
  3. ...
  4. Pair[] testPairs = {
  5. new Pair<>("apple", "James"),
  6. new Pair<>("banana", "John"),
  7. new Pair<>("grapes", "Tom"),
  8. new Pair<>("apple", "Jenkins"),
  9. new Pair<>("banana", "Edward"),
  10. new Pair<>("grapes", "Pierre")
  11. };
  12.  
  13. Map<String, List<String>> result1 = Arrays.stream(testPairs)...;
  14.  
  15. Map<String, String> result2 = Arrays.stream(testPairs)...;
  16.  
  17. Map<String, List<String>> result1 = Arrays.stream(testPairs)
  18. .collect(Collectors.groupingBy(Pair::getS,
  19. Collectors.mapping(Pair::getT, Collectors.toList())));
  20.  
  21. Map<String, String> result2 = Arrays.stream(testPairs)
  22. .collect(Collectors.toMap(Pair::getS, Pair::getT, (v1, v2) -> v1));
  23.  
  24. Map<String, List<String>> result1 = Arrays.stream(testPairs).collect(Collectors
  25. .groupingBy(p -> (String) p.getS(),
  26. Collectors.mapping(p -> (String) p.getT(), Collectors.toList())));
  27.  
  28.  
  29. Map<String, String> result2 = Arrays.stream(testPairs)
  30. .collect(Collectors.toMap(p -> (String) p.getS(), p -> (String) p.getT(), (v1, v2) -> v1));
Add Comment
Please, Sign In to add comment