I use javascript often, and find underscorejs is very handy for manipulating data set, such as array or object.
I am very new to Java, and wonder if there is similar lib for Java?
Underscore. js is a utility library that is widely used to deal with arrays, collections and objects in JavaScript. It can be used in both frontend and backend based JavaScript applications.
Because Lodash is updated more frequently than Underscore. js, a lodash underscore build is provided to ensure compatibility with the latest stable version of Underscore. js.
Updated on July 03, 2019. The dollar sign ($) and the underscore (_) characters are JavaScript identifiers, which just means that they identify an object in the same way a name would. The objects they identify include things such as variables, functions, properties, events, and objects.
There is a library underscore-java. Live example
import com.github.underscore.U;
public class Main {
public static void main(String args[]) {
String[] words = {"Gallinule", "Escambio", "Aciform", "Entortilation", "Extensibility"};
Number sum = U.chain(words)
.filter(w -> w.startsWith("E"))
.map(w -> w.length())
.sum().item();
System.out.println("Sum of letters in words starting with E... " + sum);
}
}
// Sum of letters in words starting with E... 34
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With