Created
December 17, 2017 15:11
-
-
Save Jayasagar/e89406b7a586e3226501f465924edb5e 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, List<Thing>> consumerDevicesByAge = | |
consumerList | |
.stream() | |
// filter is an intermediate operation | |
.filter(consumer -> consumer.getAge() > 30) | |
// collect is a terminal operation | |
.collect(Collectors.toMap(Consumer::getName, Consumer::getThings)); | |
// In the above code, used 'Method reference(shorthand form of lamda)' Consumer::getName which is equalent to consumer -> consumer.getName() | |
System.out.println(consumerDevicesByAge); | |
// Output: {Bob=[Thing(name=Bulb), Thing(name=MotionDetector), Thing(name=AgriFieldSensor), Thing(name=EyeVirusDetector)], Sri=[Thing(name=Bulb), Thing(name=EyeVirusDetector)]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment