JavaTuples

A more sophisticated library for tuples in Java is available, and it is called JavaTuples (available at http://www.javatuples.org/). It contains things such as, but not limited to, the following:

  • Pair
  • Triplet
  • Quartet

The library can be easily installed by adding dependencies to the app/build.gradle file:

compile 'org.javatuples:javatuples:1.2'

The use of the library is simple and very simple to the android.util.Pair, as shown:

Observable.just("UserID1", "UserID2", "UserID3")
.map(id -> Triplet.with(id, id + "-access-token",
"third-value"))
.subscribe(triplet -> log(triplet.getValue0(),
triplet.getValue1() + triplet.getValue2()));

However, the library has a much higher overhead in memory compared to android.util.Pair, because it keeps much more references and objects in memory by referencing lists and arrays internally. This might be best avoided in cases when one has to work with data sizes of millions of items.

Furthermore, using anything bigger than Triplet makes code very confusing, so the developer should prefer using their own custom classes in such cases.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.154.252