Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- List<Officer> fleetOfficers = fleet.stream().map(ship -> ship.getCrewMembers()).filter(member -> member instanceof Officer).map(member -> (Officer) member).collect(Collectors.toList());
- List<OfficerRank> ranks = fleetOfficers.stream().map(officer -> officer.getRank()).collect(Collectors.toList());
- Map<OfficerRank, Integer> rankOccurences = ranks.stream().collect(Collectors.groupingBy(rank -> rank, Collectors.reducing(0, s -> 1, Integer::sum)));
- 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