Java Tuple

Java Tuple

Tuples are a collection of objects of different types. The different types bit is what makes them different from arrays and lists. This would mean that you could have one object(with that tuple being that one object) contain all of someones identifying information, like age(int), gender(string), name(string), etc.

Ex:

Triplet<String, String, Integer> = new Triplet<String, String,Integer>(“Julia”, “female”, 20) ;

or in generalized form:

SpecificTupleType<ObjectType1,ObjectType2,etc> = new SpecificTupleType<ObjectType1,ObjectType2,etc>(Object1,Object2,etc);

That’s how you make a tuple by the way. So there are actually ten kinds of tuples, that vary bu how many objects you can have in a tuple, so for one object it would be a unit, two pair, three triplet, four quartet, etc. So the max number of objects you can have in a Tuple is 10. Also Java doesn’t have the JavaTuple data structure by default so you will need to download the JavaTuple library onto whatever platform you are using to make the program(EX.: Eclipse).

Some advantages to tuples are that they are immutable(which means you can’t change them after you have created them), they are type safe, they are serializable(which means that they can be put in the file system and can therefore be put into other applications) they can be used in iterations and they have things like toString() and equals() built into them.

Usefull Methods(will be updated with the rest of the information soon)

It’s possible I will also do one on the LabelValue and KeyValue classes.(There like another version of the pair tuple from my understanding).

Some sites to go to for more information are the tuple library which is already linked, geekforGeeks, tutorialspoints, and howtodoinjava.