Advertisement
UriSteiff

trhrth

Jun 10th, 2021
645
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1. List<Officer> fleetOfficers = fleet.stream().map(ship -> ship.getCrewMembers()).filter(member -> member instanceof Officer).map(member -> (Officer) member).collect(Collectors.toList());
  2.         List<OfficerRank> ranks = fleetOfficers.stream().map(officer -> officer.getRank()).collect(Collectors.toList());
  3.         Map<OfficerRank, Integer> rankOccurences = ranks.stream().collect(Collectors.groupingBy(rank -> rank, Collectors.reducing(0, s -> 1, Integer::sum)));
  4.         List<Map.Entry<OfficerRank, Integer>> entries = rankOccurences.entrySet().stream().sorted(Comparator.comparing(e -> e.getValue()).thenComparing(e -> e.getKey())).collect(Collectors.toList());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement