Last active
December 15, 2015 03:59
-
-
Save dlhartveld/5198058 to your computer and use it in GitHub Desktop.
Simple stream API example from the JDK 8 javadocs (see http://lambdadoc.net/api/index.html?java/util/stream/package-summary.html, b79, retrieved 2013-03-19). See for a traditional for-loop-based example: https://gist.github.com/dlhartveld/5198093
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
List<Block> blocks = /* ... */; | |
int sumOfWeights = blocks.stream() | |
.filter(b -> b.getColor() == Color.RED) | |
.map(b -> b.getWeight()) | |
.sum(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment