Java 1.6 and later.
Include the following in your pom.xml
for Maven:
<dependencies>
<dependency>
<groupId>com.github.javadev</groupId>
<artifactId>underscore</artifactId>
<version>1.43</version>
</dependency>
...
</dependencies>
Gradle:
compile 'com.github.javadev:underscore:1.43'
U.chain(/* array | list | set | map | anything based on Iterable interface */)
.filter(..)
.map(..)
...
.sortWith()
.forEach(..);
U.chain(value1, value2, value3)...
U.range(0, 10)...
U.chain(1, 2, 3) // or java.util.Arrays.asList(1, 2, 3) or new Integer[] {1, 2, 3}
.filter(v -> v > 1)
// 2, 3
.map(v -> v + 1)
// 3, 4
.sortWith((a, b) -> b.compareTo(a))
// 4, 3
.forEach(System.out::println);
// 4, 3
Underscore-java is a java port of Underscore.js.
In addition to porting Underscore's functionality, Underscore-java includes matching unit tests.
For docs, license, tests, and downloads, see: http://javadev.github.io/underscore-java
Thanks to Jeremy Ashkenas and all contributors to Underscore.js.