Created
December 17, 2017 15:15
-
-
Save Jayasagar/17a73d9ec8e19c3a70dc97d45372ccad to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // How to loop nested collection using lambda streams? | |
| Set<Event> allActiveDeviceOperations = consumerList | |
| .stream() | |
| // 'flatMap' intermediate operation, here produces the stream of user Things(Devices) | |
| .flatMap(consumer -> consumer.getThings().stream()) | |
| .filter(thing -> thing.isRunning()) | |
| .flatMap(thing -> thing.getEvents().stream()) | |
| .collect(Collectors.toSet()); | |
| System.out.println(allActiveDeviceOperations); | |
| //Output : [Event(name=motionCaptured), Event(name=switchedOff), Event(name=switchedOn), Event(name=virusFound), Event(name=dryField)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment