Tuple is a sequence of objects which may or may not be of same type. Consider the following example −
Above object is a tuple of three elements, an Integer, a string and a Connection Object.
JavaTuples is a very simple library which offers ten different tuple classses which are sufficient to handle most of the tuple related requirements.
Unit<A> - 1 element
Pair<A,B> - 2 elements
Triplet<A,B,C> - 3 elements
Quartet<A,B,C,D> - 4 elements
Quintet<A,B,C,D,E> - 5 elements
Sextet<A,B,C,D,E,F> - 6 elements
Septet<A,B,C,D,E,F,G> - 7 elements
Octet<A,B,C,D,E,F,G,H> - 8 elements
Ennead<A,B,C,D,E,F,G,H,I> - 9 elements
Decade<A,B,C,D,E,F,G,H,I,J> - 10 elements
Apart from these tuple classes, JavaTuples also provides two additional classes for semantics sake.
All tuple classes are typesafe and immutable and implements following interfaces and methods.
List or Array can contain any number of elements but each element must be of same type whereas tuples can contain only specific number of elements, can have different type of elements but still are typesafe.