Alex Rivera | Logout

Using Pairs or 2-tuples in Java

Asked 2010-04-19T21:20:16.530
376

My Hashtable in Java would benefit from a value having a tuple structure. What data structure can I use in Java to do that?

Hashtable<Long, Tuple<Set<Long>,Set<Long>>> table = ...
Edit
Report

2 Answers

189

javatuples is a dedicated project for tuples in Java.

Unit<A> (1 element)
Pair<A,B> (2 elements)
Triplet<A,B,C> (3 elements)
answered 2012-05-17T07:41:37.353
126

Apache Commons provided some common java utilities including a Pair. It implements Map.Entry, Comparable and Serializable.

answered 2013-03-01T14:10:12.837

Your Answer