A Septet is a Tuple from JavaTuples library that deals with 3 elements. Since this Septet is a generic class, it can hold any type of value in it.
Since Septet is a Tuple, hence it also has all the characteristics of JavaTuples:
- They are Typesafe
- They are Immutable
- They are Iterable
- They are Serializable
- They are Comparable (implements Comparable<Tuple>)
- They implement equals() and hashCode()
- They also implement toString()
Class Declaration
public final class Septet<A, B, C, D, E, F, G> extends Tuple
implements IValue0<A>, IValue1<B>, IValue2<C>, IValue3<D>, IValue4<E>, IValue5<F, IValue6<G>
Class hierarchy
Object
↳ org.javatuples.Tuple
↳ org.javatuples.Septet<A, B, C, D, E, F, G>
Creating Septet Tuple
Septet<A, B, C, D, E, F, G> septet =
new Septet<A, B, C, D, E, F, G>
(value1, value2, value3, value4, value5, value6, value7);
Java
// Below is a Java program to create
// a Septet tuple from Constructor
import java.util.*;
import org.javatuples.Septet;
class GfG {
public static void main(String[] args)
{
Septet<Integer, Integer.Integer, Integer, Integer, Integer, Integer> septet
= Septet.with(Integer.valueOf(1),
Integer.valueOf(2),
Integer.valueOf(3),
Integer.valueOf(4),
Integer.valueOf(5),
Integer.valueOf(6),
Integer.valueOf(7));
System.out.println(septet);
}
}
[1, 2, 3, 4, 5, 6, 7]
- Using with() method: The with() method is a function provided by the JavaTuples library, to instantiate the object with such values.
Syntax:
Septet<type1, type2, type3, type4, type5, type6, type7> septet =
Septet.with(value1, value2, value3, value4, value5, value6, value7);
Java
// Below is a Java program to create
// a Septet tuple from with() method
import java.util.*;
import org.javatuples.Septet;
class GfG {
public static void main(String[] args)
{
Septet<Integer, Integer.Integer, Integer, Integer, Integer, Integer> septet
= Septet.with(Integer.valueOf(1),
Integer.valueOf(2),
Integer.valueOf(3),
Integer.valueOf(4),
Integer.valueOf(5),
Integer.valueOf(6),
Integer.valueOf(7));
System.out.println(septet);
}
}
[1, 2, 3, 4, 5, 6, 7]
- From other collections: The fromCollection() method is used to create a Tuple from a collection, and fromArray() method is used to create from an array. The collection/array must have the same type as of the Tuple and the number of values in the collection/array must match the Tuple class.
Syntax:
Septet<type1, type2, type3, type4, type5, type6, type7> septet =
Septet.fromCollection(collectionWith_7_value);
Septet<type1, type2, type3, type4, type5, type6, type7> septet =
Septet.fromArray(arrayWith_7_value);
Java
// Below is a Java program to create
// a Septet tuple from Collection
import java.util.*;
import org.javatuples.Septet;
class GfG {
public static void main(String[] args)
{
// Creating Septet from List
List<Integer> list = new ArrayList<Integer>();
list.add(1);
list.add(2);
list.add(3);
list.add(4);
list.add(5);
list.add(6);
list.add(7);
Septet<Integer, Integer, Integer, Integer, Integer, Integer> septet
= Septet.fromCollection(list);
// Creating Septet from Array
Integer[] arr = { 1, 2, 3, 4, 5, 6, 7 };
Septet<Integer, Integer, Integer, Integer, Integer, Integer> otherSeptet
= Septet.fromArray(arr);
System.out.println(septet);
System.out.println(otherSeptet);
}
}
[1, 2, 3, 4, 5, 6, 7]
[1, 2, 3, 4, 5, 6, 7]
Getting value
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:
Septet<type1, type2, type3, type4, type5, type6, type7> septet =
new Septet<type1, type2, type3, type4, type5, type6, type7>
(value1, value2, value3, value4, value5, value6, value7);
type1 val1 = septet.getValue0();
Example:
Java
// Below is a Java program to get
// a Septet value
import java.util.*;
import org.javatuples.Septet;
class GfG {
public static void main(String[] args)
{
Septet<Integer, Integer.Integer, Integer, Integer, Integer, Integer> septet
= Septet.with(Integer.valueOf(1),
Integer.valueOf(2),
Integer.valueOf(3),
Integer.valueOf(4),
Integer.valueOf(5),
Integer.valueOf(6),
Integer.valueOf(7));
System.out.println(septet.getValue0());
System.out.println(septet.getValue2());
}
}
Output:
1
3
Setting Septet Value
Since the Tuples are immutable, it means that modifying a value at any 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:
Septet<type1, type2, type3, type4, type5, type6, type7> septet =
new Septet<type1, type2, type3, type4, type5, type6, type7>
(value1, value2, value3, value4, value5, value6, value7);
Septet<type1, type2, type3, type4, type5, type6, type7>
otherSeptet = septet.setAtX(value);
Example:
Java
// Below is a Java program to set
// a Septet value
import java.util.*;
import org.javatuples.Septet;
class GfG {
public static void main(String[] args)
{
Septet<Integer, Integer.Integer, Integer, Integer, Integer, Integer> septet
= Septet.with(Integer.valueOf(1),
Integer.valueOf(2),
Integer.valueOf(3),
Integer.valueOf(4),
Integer.valueOf(5),
Integer.valueOf(6),
Integer.valueOf(7));
Septet<Integer, Integer.Integer, Integer, Integer, Integer, Integer> otherSeptet
= septet.setAt3(40);
System.out.println(otherSeptet);
}
}
Output:
[1, 2, 3, 40, 5, 6, 7]
Adding a Value
Adding a value can be done with the help of addAtX() method, where X represent the index at which the value is to be added. This method returns a Tuple of element one more than the called Tuple.
Syntax:
Septet<type1, type2, type3, type4, type5, type6, type7> septet =
new Septet<type1, type2, type3, type4, type5, type6, type7>
(value1, value2, value3, value4, value5, value6, value7);
Septet<type 1, type 2, type 3, type 4, type 5, type 6, type 7> septet =
septet.addAtx(value);
Example:
Java
// Below is a Java program to add
// a value
import java.util.*;
import org.javatuples.Septet;
import org.javatuples.Octet;
class GfG {
public static void main(String[] args)
{
Septet<Integer, Integer.Integer, Integer, Integer, Integer, Integer> septet
= Septet.with(Integer.valueOf(1),
Integer.valueOf(2),
Integer.valueOf(3),
Integer.valueOf(4),
Integer.valueOf(5),
Integer.valueOf(6),
Integer.valueOf(7));
Octet<Integer, Integer, Integer.Integer, Integer, Integer, Integer, Integer> octet
= septet.addAt7(8);
System.out.println(octet);
}
}
Output:
[1, 2, 3, 4, 5, 6, 7, 8]
Searching in Septet
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:
Septet<type1, type2, type3, type4, type5, type6, type7> septet =
new Septet<type1, type2, type3, type4, type5, type6, type7>
(value1, value2, value3, value4, value5, value6, value7);
boolean res = septet.contains(value2);
Example:
Java
// Below is a Java program to search
// a value in a Septet
import java.util.*;
import org.javatuples.Septet;
class GfG {
public static void main(String[] args)
{
Septet<Integer, Integer.Integer, Integer, Integer, Integer, Integer> septet
= Septet.with(Integer.valueOf(1),
Integer.valueOf(2),
Integer.valueOf(3),
Integer.valueOf(4),
Integer.valueOf(5),
Integer.valueOf(6),
Integer.valueOf(7));
boolean exist = septet.contains(5);
boolean exist1 = septet.contains(false);
System.out.println(exist);
System.out.println(exist1);
}
}
Output:
true
false
Iterating through Septet
Since Septet implement the Iterable<Object> interface. It means that they can be iterated in the same way as collections or arrays.
Syntax:
Septet<type1, type2, type3, type4, type5, type6, type7> septet =
new Septet<type1, type2, type3, type4, type5, type6, type7>
(value1, value2, value3, value4, value5, value6, value7);
for (Object item : septet) {
...
}
Example:
Java
// Below is a Java program to iterate
// a Septet
import java.util.*;
import org.javatuples.Septet;
class GfG {
public static void main(String[] args)
{
Septet<Integer, Integer.Integer, Integer, Integer, Integer, Integer> septet
= Septet.with(Integer.valueOf(1),
Integer.valueOf(2),
Integer.valueOf(3),
Integer.valueOf(4),
Integer.valueOf(5),
Integer.valueOf(6),
Integer.valueOf(7));
for (Object item : septet)
System.out.println(item);
}
}
Output:
1
2
3
4
5
6
7
Similar Reads
JavaTuples | Introduction
Tuple The word "tuple" means "a data structure consisting of multiple parts". Hence Tuples can be defined as a data structure that can hold multiple values and these values may/may not be related to each other. Example: [Geeks, 123, *@] In this example, the values in the tuple are not at all relat
6 min read
Unit Class in JavaTuples
The Unit class in JavaTuples is a tuple with no values. It is often used as a placeholder when you need to represent an empty tuple, for example, as the second value in a Pair when you only need the first value. The Unit class is a subclass of the Tuple class, which means that it has all the methods
7 min read
Pair Class in JavaTuples
A Pair is a Tuple from JavaTuples library that deals with 2 elements. Since this Pair is a generic class, it can hold any type of value in it.Since Pair is a Tuple, hence it also has all the characteristics of JavaTuples:Â They are TypesafeThey are ImmutableThey are IterableThey are SerializableThey
5 min read
Triplet Class in JavaTuples
A Triplet is a Tuple from JavaTuples library that deals with 3 elements. Since this Triplet is a generic class, it can hold any type of value in it. Since Triplet is a Tuple, hence it also has all the characteristics of JavaTuples:Â They are TypesafeThey are ImmutableThey are IterableThey are Serial
5 min read
Quartet Class in JavaTuples
A Quartet is a Tuple from JavaTuples library that deals with 4 elements. Since this Quartet is a generic class, it can hold any type of value in it. Since Quartet is a Tuple, hence it also has all the characteristics of JavaTuples:Â They are TypesafeThey are ImmutableThey are IterableThey are Serial
5 min read
Quintet Class in JavaTuples
A Quintet is a Tuple from JavaTuples library that deals with 3 elements. Since this Quintet is a generic class, it can hold any type of value in it.Since Quintet is a Tuple, hence it also has all the characteristics of JavaTuples:Â Â They are TypesafeThey are ImmutableThey are IterableThey are Serial
5 min read
Sextet Class in JavaTuples
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:Â Â They are TypesafeThey are ImmutableThey are IterableThey are Serializa
6 min read
Septet Class in JavaTuples
A Septet is a Tuple from JavaTuples library that deals with 3 elements. Since this Septet is a generic class, it can hold any type of value in it.Since Septet is a Tuple, hence it also has all the characteristics of JavaTuples:Â Â They are TypesafeThey are ImmutableThey are IterableThey are Serializa
6 min read
Octet Class in JavaTuples
A Octet is a Tuple from JavaTuples library that deals with 3 elements. Since this Octet is a generic class, it can hold any type of value in it.Since Octet is a Tuple, hence it also has all the characteristics of JavaTuples:Â Â They are TypesafeThey are ImmutableThey are IterableThey are Serializable
6 min read
Ennead Class in JavaTuples
A Ennead is a Tuple from JavaTuples library that deals with 9 elements. Since this Ennead is a generic class, it can hold any type of value in it. Since Ennead is a Tuple, hence it also has all the characteristics of JavaTuples:Â They are TypesafeThey are ImmutableThey are IterableThey are Serializa
6 min read