![]() |
VOOZH | about |
A Sextet is a Tuple from JavaTuples library that deals with 3 elements. Since this Sextet is a generic class, it can hold any type of value in it.
Since Sextet is a Tuple, hence it also has all the characteristics of JavaTuples:
public final class Sextet<A, B, C, D, E, F> extends Tuple implements IValue0<A>, IValue1<B>, IValue2<C>, IValue3<D>, IValue4<E>, IValue5<F>
Object ↳ org.javatuples.Tuple ↳ org.javatuples.Sextet<A, B, C, D, E, F>
Sextet<A, B, C, D, E, F> sextet = new Sextet<A, B, C, D, E. F> (value1, value2, value3, value4, value5, value6);
[1, 2, 3, 4, 5, 6]
Sextet<type1, type2, type3, type4, type5, type6> sextet = Sextet.with(value1, value2, value3, value4, value5, value6);
[1, 2, 3, 4, 5, 6]
Sextet<type1, type2, type3, type4, type5, type6> sextet = Sextet.fromCollection(collectionWith_6_value); Sextet<type1, type2, type3, type4, type5, type6> sextet = Sextet.fromArray(arrayWith_6_value);
[1, 2, 3, 4, 5, 6] [1, 2, 3, 4, 5, 6]
The getValueX() method can be used to fetch the value in a Tuple at index X. The indexing in Tuples start with 0. Hence the value at index X represents the value at position X+1.
Syntax:
Sextet<type1, type2, type3, type4, type5, type6> sextet = new Sextet<type1, type2, type3, type4, type5, type6> (value1, value2, value3, value4, value5, value6); type1 val1 = sextet.getValue0();
Example:
Output:
1 3
Since the Tuples are immutable, it means that modifying a value at an index is not possible. Hence JavaTuples offer setAtX(value) which creates a copy of the Tuple with a new value at index X, and returns that Tuple.
Syntax:
Sextet<type1, type2, type3, type4, type5, type6> sextet = new Sextet<type1, type2, type3, type4, type5, type6> (value1, value2, value3, value4, value5, value6); Sextet<type1, type2, type3, type4, type5, type6> otherSextet = sextet.setAtX(value);
Example:
Output:
[1, 2, 3, 40, 5, 6]
Adding a value can be done with the help of addAtX() method, where X represents the index at which the value is to be added. This method returns a Tuple of element one more than the called Tuple.
Syntax:
Sextet<type1, type2, type3, type4, type5, type6> sextet = new Sextet<type1, type2, type3, type4, type5, type6> (value1, value2, value3, value4, value5, value6); Sextet<type 1, type 2, type 3, type 4, type 5, type 6> sextet = sextet.addAtx(value);
Example:
Output:
[1, 2, 3, 4, 5, 6, 7]
An element can be searched in a tuple with the pre-defined method contains(). It returns a boolean value whether the value is present or not.
Syntax:
Sextet<type1, type2, type3, type4, type5, type6> sextet = new Sextet<type1, type2, type3, type4, type5, type6> (value1, value2, value3, value4, value5, value6); boolean res = sextet.contains(value2);
Example:
Output:
true false
Since Sextet implement the Iterable<Object> interface. It means that they can be iterated in the same way as collections or arrays.
Syntax:
Sextet<type1, type2, type3, type4, type5, type6> sextet =
new Sextet<type1, type2, type3, type4, type5, type6>
(value1, value2, value3, value4, value5, value6);
for (Object item : sextet) {
...
}
Example:
Output:
1 2 3 4 5 6