A Java collection of value pairs? (tuples?)

后端 未结 19 2297
名媛妹妹
名媛妹妹 2020-11-22 05:43

I like how Java has a Map where you can define the types of each entry in the map, for example .

What I\'m looking for is a type

19条回答
  •  抹茶落季
    2020-11-22 05:49

    In project Reactor (io.projectreactor:reactor-core) there is advanced support for n-Tuples:

    Tuple2 t = Tuples.of("string", 1)
    

    There you can get t.getT1(), t.getT2(), ... Especially with Stream or Flux you can even map the tuple elements:

    Stream> s;
    s.map(t -> t.mapT2(i -> i + 2));
    

提交回复
热议问题