You can extract all elements from a tuple in one statement by declaring a set of variable using the Variable generic type. The Variable type takes one parameter, which must match the type of the element. Then use the extract() method to remove an element from the tuple and store it in a variable. Chain extract() calls together to get all elements.

Variable<String> v1 = new Variable<String>();
Variable<Integer> v2 = new Variable<Integer>();

Tuple.from("Hello", 42).extract(v1).extract(v2);

Use the get() method to access the value of a Variable object.

String e1 = v1.get();
int e2 = v2.get();

As an alternative, you can get an element directly from a tuple using one of the getn() methods. The n is replaced with the 1-based index of the element you want to get. So get1() will return the first element, and get3() will return the third.

Pair<String, Integer> t = Tuple.from("Hello", 42);
String e1 = Tuple.get1(t);
int e2 = Tuple.get2(t);

There are only 10 getn() methods, so this technique is not as flexible as the extract() method. And this technique cannot be used to extract all variables in one statement. As a result, the tuple must be stored, which means that the type must be expressed. For small tuples of named types, this is not difficult. But if the tuple gets large or does not use a named type, it may be easier to extract all members without storing the tuple itself.