Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a underscore.js lib for java?

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?

like image 211
Nicolas S.Xu Avatar asked Jan 05 '15 01:01

Nicolas S.Xu


People also ask

Can you use underscore in JavaScript?

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.

Which is better underscore or Lodash?

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.

What does the underscore mean in 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.


1 Answers

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
like image 104
Valentyn Kolesnikov Avatar answered Oct 06 '22 00:10

Valentyn Kolesnikov