Does Java SE 8 have Pairs or Tuples?

前端 未结 9 889
独厮守ぢ
独厮守ぢ 2020-11-28 18:37

I am playing around with lazy functional operations in Java SE 8, and I want to map an index i to a pair / tuple (i, value[i]), then <

9条回答
  •  广开言路
    2020-11-28 19:34

    Vavr (formerly called Javaslang) (http://www.vavr.io) provides tuples (til size of 8) as well. Here is the javadoc: https://static.javadoc.io/io.vavr/vavr/0.9.0/io/vavr/Tuple.html.

    This is a simple example:

    Tuple2 entry = Tuple.of(1, "A");
    
    Integer key = entry._1;
    String value = entry._2;
    

    Why JDK itself did not come with a simple kind of tuples til now is a mystery to me. Writing wrapper classes seems to be an every day business.

提交回复
热议问题