Giter Club home page Giter Club logo

underscore-java's Introduction


Maven Central MIT License Java CI CodeQL Coverage Status codecov CircleCI Codeship Status for javadev/underscore-java Build status Build Status Known Vulnerabilities Code Scene javadoc Quality Gate Status Maintainability Rating Scrutinizer Build Status Hits-of-Code Java Version

Join the chat at


Java 1.8 and later or Java 11.


Include the following in your pom.xml for Maven:



implementation 'com.github.javadev:underscore:1.78'


U.of(/* array | list | set | map | anything based on Iterable interface */)
U.of(value1, value2, value3)...
U.range(0, 10)...

U.of(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
U.of(1, 2, 3) // or java.util.Arrays.asList(1, 2, 3) or new Integer[] {1, 2, 3}
    .mapMulti((num, consumer) -> {
        for (int i = 0; i < num; i++) {
            consumer.accept("a" + num);
    // "a1", "a2", "a2", "a3", "a3", "a3"
    // <a>
    //    <b>data</b>
    // </a>

    // {
    //    "a": {
    //      "b": "data"
    //    }
    // }

U.xmlToJson("<a attr=\"c\"><b>data</b></a>");
    // {
    //   "a": {
    //     "-attr": "c",
    //     "b": "data"
    //   },
    //   "#omit-xml-declaration": "yes"
    // }

    // <?xml version="1.0" encoding="UTF-8"?>
    // <a attr="c">
    //   <b>data</b>
    // </a>

U.Builder builder = U.objectBuilder()
    .add("firstName", "John")
    .add("lastName", "Smith")
    .add("age", 25)
    .add("address", U.arrayBuilder()
            .add("streetAddress", "21 2nd Street")
            .add("city", "New York")
            .add("state", "NY")
            .add("postalCode", "10021")))
    .add("phoneNumber", U.arrayBuilder()
            .add("type", "home")
            .add("number", "212 555-1234"))
            .add("type", "fax")
            .add("number", "646 555-4567")));
  "firstName": "John",
  "lastName": "Smith",
  "age": 25,
  "address": [
      "streetAddress": "21 2nd Street",
      "city": "New York",
      "cityId": null,
      "state": "NY",
      "postalCode": "10021"
  "phoneNumber": [
      "type": "home",
      "number": "212 555-1234"
      "type": "fax",
      "number": "646 555-4567"
<?xml version="1.0" encoding="UTF-8"?>
  <age number="true">25</age>
  <address array="true">
    <streetAddress>21 2nd Street</streetAddress>
    <city>New York</city>
    <cityId null="true"/>
    <number>212 555-1234</number>
    <number>646 555-4567</number>

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:

Thanks to Jeremy Ashkenas and all contributors to Underscore.js.

underscore-java's People


borosh avatar dependabot[bot] avatar happyfacade avatar javadev avatar lalayang avatar psobot avatar sidharthkuruvila avatar skezzowski avatar szkocsovszki avatar terhesb avatar xhaggi avatar



Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.