Skip to content

Instantly share code, notes, and snippets.

@dlhartveld
Last active December 15, 2015 03:59
Show Gist options
  • Save dlhartveld/5198058 to your computer and use it in GitHub Desktop.
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
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