Created
December 17, 2017 15:21
-
-
Save Jayasagar/941733ac396f71d3c9c67b55eb36725d to your computer and use it in GitHub Desktop.
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, Optional<Integer>> highestDeviceCostCustomerPaid = consumerList | |
.stream() | |
.flatMap(consumer -> consumer.getThings() | |
.stream() | |
.map(thing -> new AbstractMap.SimpleImmutableEntry<>(consumer.getName(), thing.getCost())) | |
) | |
.collect(Collectors.groupingBy(entry -> entry.getKey(), | |
Collectors.mapping(entry -> entry.getValue(), Collectors.maxBy(Comparator.comparingInt(value -> value))))); | |
System.out.println(highestDeviceCostCustomerPaid); | |
// Output: {Bob=Optional[300], Satti=Optional[300], Sri=Optional[200], Malli=Optional[120]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment