Created
June 21, 2012 20:42
-
-
Save hertzsprung/2968389 to your computer and use it in GitHub Desktop.
Functional computation on a collection
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<String> names = Arrays.asList("Alice", "Bob", "Charlie", "Dave"); | |
names | |
.mapped(e -> { return e.length(); }) | |
.asIterable() // returns an Iterable of BiValue elements | |
// an element's key is the person's name, its value is the string length | |
.filter(e -> e.getValue() >= 4) | |
.sorted((a, b) -> a.getValue() - b.getValue()) | |
.forEach(e -> { System.out.println(e.getKey() + '\t' + e.getValue()); }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated version of this code using the recent APIs: