Category: 08. Java Tuples

https://cdn-icons-png.flaticon.com/512/226/226777.png

  • LabelValues Class

    Introduction

    The org.javatuples.LabelValue class represents a Tuple with two elements with positions 0 and 1 renamed as “label” and “value”, respectively.

    Class Declaration

    Following is the declaration for org.javatuples.LabelValue class −

    public final class LabelValue<A,B>
       extends Tuple
    
      implements IValue0&lt;A&gt;, IValue1&lt;B&gt;

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Class Constructor

    Sr.No.Constructor & Description
    1LabelValue(A value0, B value1)This creates a LabelValue Tuple.

    Class Methods

    Sr.No.Method & Description
    1static <X> LabelValue<X,X> fromArray(X[] array)Create tuple from array.
    2static <X> LabelValue<X,X> fromCollection(Collection<X> collection)Create tuple from collection.
    3static <X> LabelValue<X,X> fromIterable(Iterable<X> iterable)Create tuple from iterable.
    4static <X> LabelValue<X,X> fromIterable(Iterable<X> iterable, int index)Create tuple from iterable, starting from the specified index.
    5A getLabel()Return the label.
    6int getSize()Return the size of the tuple.
    7A getValue()Returns the value of the tuple.
    8<X> LabelValue<X,B> setLabel(X label)set the label and return the tuple.
    9<X> LabelValue<A,Y> setValue(Y value)set the value and return the tuple.
    10static <A,B> LabelValue<A,B> with(A value0, B value1)Create the tuple using given value.

    Methods inherite

    This class inherits methods from the following classes −

    • org.javatuples.Tuple
    • Object

    Example

    Let’s see LabelValue Class in action. Here we’ll see how to use various methods.

    Create a java class file named TupleTester in C:\>JavaTuples.

    File: TupleTester.java

    package com.tutorialspoint;
    import java.util.ArrayList;
    import java.util.List;
    import org.javatuples.LabelValue;
    public class TupleTester {
       public static void main(String args[]){
    
      LabelValue&lt;Integer, Integer&gt; labelValue = LabelValue.with(5,6);
      System.out.println(labelValue);
      List&lt;Integer&gt; list = new ArrayList&lt;&gt;();
      list.add(1);
      list.add(2);
      Integer label = labelValue.getLabel();
      System.out.println(label);
      Integer value = labelValue.getValue();
      System.out.println(value);
      LabelValue&lt;Integer, Integer&gt; labelValue1 
         = LabelValue.fromCollection(list);   
      System.out.println(labelValue1);
    } }

    Verify the result

    Compile the classes using javac compiler as follows −

    C:\JavaTuples>javac -cp javatuples-1.2.jar ./com/tutorialspoint/TupleTester.java
    

    Now run the TupleTester to see the result −

    C:\JavaTuples>java  -cp .;javatuples-1.2.jar com.tutorialspoint.TupleTester
    

    Output

    Verify the Output

    [5, 6]
    5
    6
    [1, 2]
    
  • Decade Class

    Introduction

    The org.javatuples.Decade class represents a Tuple with ten elements.

    Class Declaration

    Following is the declaration for org.javatuples.Decade class −

    public final class Decade<A, B, C, D, E, F, G, H, I, J>
       extends Tuple
    
      implements IValue0&lt;A&gt;, IValue1&lt;B&gt;, 
         IValue2&lt;C&gt;, IValue3&lt;D&gt;, IValue4&lt;E&gt;,
            IValue5&lt;F&gt;, IValue6&lt;G&gt;, IValue7&lt;H&gt;,
               IValue8&lt;I&gt;, IValue9&lt;J&gt;

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Class Constructor

    Sr.No.Constructor & Description
    1Decade(A value0, B value1, C value2, D value3, E value4, F value5, G value6, H value7, I value8, I value9 )This creates a Decade Tuple.

    Class Methods

    Similarly setAt1() upto setAt9() set the value at index 1, and so on.

    Sr.No.Method & Description
    1static <X> Decade<X,X,X,X,X,X,X,X,X,X > fromArray(X[] array)Create tuple from array.
    2static <X> Decade<X,X,X,X,X,X,X,X,X,X> fromCollection(Collection<X> collection)Create tuple from collection.
    3static <X> Decade<X,X,X,X,X,X,X,X,X,X> fromIterable(Iterable<X> iterable)Create tuple from iterable.
    4static <X> Decade<X,X,X,X,X,X,X,X,X> fromIterable(Iterable<X> iterable, int index)Create tuple from iterable, starting from the specified index.
    5int getSize()Return the size of the tuple.
    6A getValue0()Returns the value of the tuple at index 0.Similarly getValue1() upto getValue9() returns the value at index 1 and so on.
    7Ennead<B,C,D,E,F,G,H,I,J> removeFrom0()Return the tuple after removing value of the tuple at index 0.Similarly removeFrom1() upto removeFrom9() returns the tuple after removing value of the tuple at index 1 and so on.
    8<X> Decade<X,B,C,D,E,F,G,H,I,J> setAt0(X value)Set the value of the tuple at index 0.
    9static <A> Decade<A,B,C,D,E,F,G,H,I,J> with(A value0, B value1, C value2, D value3, E value4, F value5, G value6, H value7, I value8, I value9)Create the tuple using given value.

    Methods inherite

    This class inherits methods from the following classes −

    • org.javatuples.Tuple
    • Object

    Example

    Let’s see Ennead Class in action. Here we’ll see how to use various methods.

    Create a java class file named TupleTester in C:\>JavaTuples.

    File: TupleTester.java

    package com.tutorialspoint;
    import java.util.ArrayList;
    import java.util.List;
    import org.javatuples.Decade;
    import org.javatuples.Ennead;
    public class TupleTester {
       public static void main(String args[]){
    
      Decade&lt;Integer, Integer, Integer, Integer, 
         Integer,Integer,Integer,Integer, Integer, Integer&gt; 
      decade = Decade.with(5, 6, 7,8,9,10,11,12,13,14);
      System.out.println(decade);
      boolean isPresent = decade.contains(5);
      System.out.println("5 is present: " + isPresent);
      List&lt;Integer&gt; list = new ArrayList&lt;&gt;();
      list.add(1);
      list.add(2);
      list.add(3);
      list.add(4);
      list.add(5);
      list.add(6);
      list.add(7);
      list.add(8);
      list.add(9);
      list.add(10);
      Integer value = decade.getValue0();
      System.out.println(value);
      Ennead&lt;Integer, Integer, Integer, Integer,Integer, 
         Integer,Integer, Integer, Integer&gt; ennead = decade.removeFrom0();
      System.out.println(ennead);
      Decade&lt;Integer, Integer, Integer, Integer, Integer,
         Integer, Integer, Integer,Integer, Integer&gt; 
         decade1 = Decade.fromCollection(list);   
      System.out.println(decade1);
    } }

    Verify the result

    Compile the classes using javac compiler as follows −

    C:\JavaTuples>javac -cp javatuples-1.2.jar ./com/tutorialspoint/TupleTester.java
    

    Now run the TupleTester to see the result −

    C:\JavaTuples>java  -cp .;javatuples-1.2.jar com.tutorialspoint.TupleTester
    

    Output

    Verify the Output

    [5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
    5 is present: true
    5
    [6, 7, 8, 9, 10, 11, 12, 13, 14]
    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    
  • Ennead Class

    Introduction

    The org.javatuples.Ennead class represents a Tuple with nine elements.

    Class Declaration

    Following is the declaration for org.javatuples.Ennead class −

    public final class Ennead<A, B, C, D, E, F, G, H, I>
       extends Tuple
    
      implements IValue0&lt;A&gt;, IValue1&lt;B&gt;, 
         IValue2&lt;C&gt;, IValue3&lt;D&gt;, IValue4&lt;E&gt;,
            IValue5&lt;F&gt;, IValue6&lt;G&gt;, IValue7&lt;H&gt;,
               IValue8&lt;I&gt;

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Class Constructor

    Sr.No.Constructor & Description
    1Ennead(A value0, B value1, C value2, D value3, E value4, F value5, G value6, H value7, I value8)This creates a Ennead Tuple.

    Class Methods

    Similarly setAt1() upto setAt8() set the value at index 1, and so on.

    Sr.No.Method & Description
    1Decade add(Unit tuple)This method returns a Decade tuple.
    2Decade add(X0 value)This method add a value to the tuple and returns a Decade tuple.
    3Decade addAt0(Unit value)This method add a Unit tuple at index 0 and returns a Decade tuple.Other similar method are addAt1(Unit value) which add a unit at index0 and have similar methods upto addAt8(Unit).
    4Decade addAt0(X0 value)This method add a value at index 0 and returns a Decade tuple.Other similar method are addAt1(X0 value) which add a value at index0 and have similar methods upto addAt8() with one parameter.
    5static <X> Ennead<X,X,X,X,X,X,X,X,X > fromArray(X[] array)Create tuple from array.
    6static <X> Ennead<X,X,X,X,X,X,X,X,X> fromCollection(Collection<X> collection)Create tuple from collection.
    7static <X> Ennead<X,X,X,X,X,X,X,X,X> fromIterable(Iterable<X> iterable)Create tuple from iterable.
    8static <X> Ennead<X,X,X,X,X,X,X,X> fromIterable(Iterable<X> iterable, int index)Create tuple from iterable, starting from the specified index.
    9int getSize()Return the size of the tuple.
    10A getValue0()Returns the value of the tuple at index 0.Similarly getValue1() upto getValue8() returns the value at index 1 and so on.
    11Octet<B,C,D,E,F,G,H,I> removeFrom0()Return the tuple after removing value of the tuple at index 0.Similarly removeFrom1() upto removeFrom8() returns the tuple after removing value of the tuple at index 1 and so on.
    12<X> Ennead<X,B,C,D,E,F,G,H,I> setAt0(X value)Set the value of the tuple at index 0.
    13static <A> Ennead<A,B,C,D,E,F,G,H,I> with(A value0, B value1, C value2, D value3, E value4, F value5, G value6, H value7, I value8)Create the tuple using given value.

    Methods inherite

    This class inherits methods from the following classes −

    • org.javatuples.Tuple
    • Object

    Example

    Let’s see Ennead Class in action. Here we’ll see how to use various methods.

    Create a java class file named TupleTester in C:\>JavaTuples.

    File: TupleTester.java

    package com.tutorialspoint;
    
    import java.util.ArrayList;
    import java.util.List;
    import org.javatuples.Decade;
    import org.javatuples.Ennead;
    import org.javatuples.Octet;
    public class TupleTester {
       public static void main(String args[]){
    
      Ennead&lt;Integer, Integer, Integer, Integer, Integer,
         Integer,Integer,Integer, Integer&gt; 
      ennead = Ennead.with(5, 6, 7,8,9,10,11,12,13);
      System.out.println(ennead);
      boolean isPresent = ennead.contains(5);
      System.out.println("5 is present: " + isPresent);
      List&lt;Integer&gt; list = new ArrayList&lt;&gt;();
      list.add(1);
      list.add(2);
      list.add(3);
      list.add(4);
      list.add(5);
      list.add(6);
      list.add(7);
      list.add(8);
      list.add(9);
      Decade&lt;Integer, Integer, Integer, Integer, Integer, 
         Integer, Integer, Integer, Integer, String&gt; decade = ennead.add("Test");
      System.out.println(decade);
      Integer value = ennead.getValue0();
      System.out.println(value);
      Octet&lt;Integer, Integer, Integer, Integer,Integer, 
         Integer,Integer, Integer&gt; octet = ennead.removeFrom0();
      System.out.println(octet);
      Ennead&lt;Integer, Integer, Integer, Integer, Integer,
         Integer, Integer, Integer,Integer&gt; ennead1 = Ennead.fromCollection(list);   
      System.out.println(ennead1);
    } }

    Verify the result

    Compile the classes using javac compiler as follows −

    C:\JavaTuples>javac -cp javatuples-1.2.jar ./com/tutorialspoint/TupleTester.java
    

    Now run the TupleTester to see the result −

    C:\JavaTuples>java  -cp .;javatuples-1.2.jar com.tutorialspoint.TupleTester
    

    Output

    Verify the Output

    [5, 6, 7, 8, 9, 10, 11, 12, 13]
    5 is present: true
    [5, 6, 7, 8, 9, 10, 11, 12, 13, Test]
    5
    [6, 7, 8, 9, 10, 11, 12, 13]
    [1, 2, 3, 4, 5, 6, 7, 8, 9]
    
  • Octet Class

    Introduction

    The org.javatuples.Octet class represents a Tuple with eight elements.

    Class Declaration

    Following is the declaration for org.javatuples.Octet class −

    public final class Octet<A, B, C, D, E, F, G, H>
       extends Tuple
    
      implements IValue0&lt;A&gt;, IValue1&lt;B&gt;, 
         IValue2&lt;C&gt;, IValue3&lt;D&gt;, IValue4&lt;E&gt;,
            IValue5&lt;F&gt;, IValue6&lt;G&gt;, IValue7&lt;H&gt;

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Class Constructor

    Sr.No.Constructor & Description
    1Octet(A value0, B value1, C value2, D value3, E value4, F value5, G value6, H value7)This creates a Octet Tuple.

    Class Methods

    Similarly setAt1() upto setAt7() set the value at index 1, and so on.

    Sr.No.Method & Description
    1Ennead add(Unit tuple)This method returns a Ennead tuple.Similarly other methods to add tuples are available e.g. add(Pair tuple) returns Decade.
    2Ennead add(X0 value)This method add a value to the tuple and returns a Ennead tuple.Similarly other methods to add values are available e.g. add(X0 value0, X1 value1) returns Decade.
    3Ennead addAt0(Unit value)This method add a Unit tuple at index 0 and returns a Ennead tuple.Similarly other methods to add tuples are available e.g. addAt0(Pair value) returns Decade. Other similar method are addAt1(Unit value) which add a unit at index0 and have similar methods upto addAt7(Pair).
    4Ennead addAt0(X0 value)This method add a value at index 0 and returns a Ennead tuple.Similarly other methods to add values are available e.g. addAt0(X0 value0, X1 value1) returns Decade. Other similar method are addAt1(X0 value) which add a value at index0 and have similar methods upto addAt7() with two parameters.
    5static <X> Octet<X,X,X,X,X,X,X,X> fromArray(X[] array)Create tuple from array.
    6static <X> Octet<X,X,X,X,X,X,X,X> fromCollection(Collection<X> collection)Create tuple from collection.
    7static <X> Octet<X,X,X,X,X,X,X,X> fromIterable(Iterable<X> iterable)Create tuple from iterable.
    8static <X> Octet<X,X,X,X,X,X,X,X> fromIterable(Iterable<X> iterable, int index)Create tuple from iterable, starting from the specified index.
    9int getSize()Return the size of the tuple.
    10A getValue0()Returns the value of the tuple at index 0.Similarly getValue1() upto getValue7() returns the value at index 1 and so on.
    11Septet<B,C,D,E,F,G,H> removeFrom0()Return the tuple after removing value of the tuple at index 0.Similarly removeFrom1() upto removeFrom7() returns the tuple after removing value of the tuple at index 1 and so on.
    12<X> Octet<X,B,C,D,E,F,G,H> setAt0(X value)Set the value of the tuple at index 0.
    13static <A> Octet<A,B,C,D,E,F,G,H> with(A value0, B value1, C value2, D value3, E value4, F value5, G value6, H value7)Create the tuple using given value.

    Methods inherite

    This class inherits methods from the following classes −

    • org.javatuples.Tuple
    • Object

    Example

    Let’s see Octet Class in action. Here we’ll see how to use various methods.

    Create a java class file named TupleTester in C:\>JavaTuples.

    File: TupleTester.java

    package com.tutorialspoint;
    import java.util.ArrayList;
    import java.util.List;
    import org.javatuples.Ennead;
    import org.javatuples.Octet;
    import org.javatuples.Septet;
    public class TupleTester {
       public static void main(String args[]){
    
      Octet&lt;Integer, Integer, Integer, Integer, Integer,Integer,Integer,Integer&gt;
      octet = Octet.with(5, 6, 7,8,9,10,11,12);
      System.out.println(octet);
      boolean isPresent = octet.contains(5);
      System.out.println("5 is present: " + isPresent);
      List&lt;Integer&gt; list = new ArrayList&lt;&gt;();
      list.add(1);
      list.add(2);
      list.add(3);
      list.add(4);
      list.add(5);
      list.add(6);
      list.add(7);
      list.add(8);
      Ennead&lt;Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, String&gt;
      ennead = octet.add("Test");
      System.out.println(ennead);
      Integer value = octet.getValue0();
      System.out.println(value);
      Septet&lt;Integer, Integer, Integer, Integer,Integer, Integer,Integer&gt;
      septet = octet.removeFrom0();
      System.out.println(septet);
      Octet&lt;Integer, Integer, Integer, Integer, Integer,Integer, Integer, Integer&gt; 
      octet1 = Octet.fromCollection(list);   
      System.out.println(octet1);
    } }

    Verify the result

    Compile the classes using javac compiler as follows −

    C:\JavaTuples>javac -cp javatuples-1.2.jar ./com/tutorialspoint/TupleTester.java
    

    Now run the TupleTester to see the result −

    C:\JavaTuples>java  -cp .;javatuples-1.2.jar com.tutorialspoint.TupleTester
    

    Output

    Verify the Output

    [5, 6, 7, 8, 9, 10, 11, 12]
    5 is present: true
    [5, 6, 7, 8, 9, 10, 11, 12, Test]
    5
    [6, 7, 8, 9, 10, 11, 12]
    [1, 2, 3, 4, 5, 6, 7, 8]
    
  • Septet Class

    Introduction

    The org.javatuples.Septet class represents a Tuple with seven elements.

    Class Declaration

    Following is the declaration for org.javatuples.Septet class −

    public final class Septet<A, B, C, D, E, F, G>
       extends Tuple
    
      implements IValue0&lt;A&gt;, IValue1&lt;B&gt;, 
         IValue2&lt;C&gt;, IValue3&lt;D&gt;, IValue4&lt;E&gt;,
            IValue5&lt;F&gt;, IValue6&lt;G&gt;

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Class Constructor

    Sr.No.Constructor & Description
    1Septet(A value0, B value1, C value2, D value3, E value4, F value5, G value6)This creates a Septet Tuple.

    Class Methods

    Similarly setAt1() upto setAt6() set the value at index 1, and so on.

    Sr.No.Method & Description
    1Octet add(Unit tuple)This method returns a Octet tuple.Similarly other methods to add tuples are available e.g. add(Pair tuple) returns Ennead and upto add(Triplet tuple) returns Decade tuple.
    2Octet add(X0 value)This method add a value to the tuple and returns a Octet tuple.Similarly other methods to add values are available e.g. add(X0 value0, X1 value1) returns Ennead and so on upto add() with three parameters.
    3Octet addAt0(Unit value)This method add a Unit tuple at index 0 and returns a Octet tuple.Similarly other methods to add tuples are available e.g. addAt0(Pair value) returns Ennead and so on upto addAt0(Triplet). Other similar method are addAt1(Unit value) which add a unit at index0 and have similar methods upto addAt6(Triplet).
    4Octet addAt0(X0 value)This method add a value at index 0 and returns a Octet tuple.Similarly other methods to add values are available e.g. addAt0(X0 value0, X1 value1) returns Ennead and so on upto addAt0() with three parameters. Other similar method are addAt1(X0 value) which add a value at index0 and have similar methods upto addAt6() with three parameters.
    5static <X> Septet<X,X,X,X,X,X,X> fromArray(X[] array)Create tuple from array.
    6static <X> Septet<X,X,X,X,X,X,X> fromCollection(Collection<X> collection)Create tuple from collection.
    7static <X> Septet<X,X,X,X,X,X,X> fromIterable(Iterable<X> iterable)Create tuple from iterable.
    8static <X> Septet<X,X,X,X,X,X,X> fromIterable(Iterable<X> iterable, int index)Create tuple from iterable, starting from the specified index.
    9int getSize()Return the size of the tuple.
    10A getValue0()Returns the value of the tuple at index 0.Similarly getValue1() upto getValue6() returns the value at index 1 and so on.
    11Sextet<B,C,D,E,F,G> removeFrom0()Return the tuple after removing value of the tuple at index 0.Similarly removeFrom1() upto removeFrom6() returns the tuple after removing value of the tuple at index 1 and so on.
    12<X> Septet<X,B,C,D,E,F,G> setAt0(X value)Set the value of the tuple at index 0.
    13static <A> Septet<A,B,C,D,E,F,G> with(A value0, B value1, C value2, D value3, E value4, F value5, G value6)Create the tuple using given value.

    Methods inherite

    This class inherits methods from the following classes −

    • org.javatuples.Tuple
    • Object

    Example

    Let’s see Septet Class in action. Here we’ll see how to use various methods.

    Create a java class file named TupleTester in C:\>JavaTuples.

    File: TupleTester.java

    package com.tutorialspoint;
    import java.util.ArrayList;
    import java.util.List;
    import org.javatuples.Septet;
    import org.javatuples.Sextet;
    import org.javatuples.Octet;
    public class TupleTester {
       public static void main(String args[]){
    
      Septet&lt;Integer, Integer, Integer, Integer, Integer,Integer,Integer&gt; septet 
         = Septet.with(5, 6, 7,8,9,10,11);
      System.out.println(septet);
      boolean isPresent = septet.contains(5);
      System.out.println("5 is present: " + isPresent);
      List&lt;Integer&gt; list = new ArrayList&lt;&gt;();
      list.add(1);
      list.add(2);
      list.add(3);
      list.add(4);
      list.add(5);
      list.add(6);
      list.add(7);
      Octet&lt;Integer, Integer, Integer, Integer, Integer, Integer, Integer, String&gt; octet 
         = septet.add("Test");
      System.out.println(octet);
      Integer value = septet.getValue0();
      System.out.println(value);
      Sextet&lt;Integer, Integer, Integer, Integer,Integer, Integer&gt; sextet 
         = septet.removeFrom0();
      System.out.println(sextet);
      Septet&lt;Integer, Integer, Integer, Integer, Integer,Integer, Integer&gt; septet1 
         = Septet.fromCollection(list);   
      System.out.println(septet1);
    } }

    Verify the result

    Compile the classes using javac compiler as follows −

    C:\JavaTuples>javac -cp javatuples-1.2.jar ./com/tutorialspoint/TupleTester.java
    

    Now run the TupleTester to see the result −

    C:\JavaTuples>java  -cp .;javatuples-1.2.jar com.tutorialspoint.TupleTester
    

    Output

    Verify the Output

    [5, 6, 7, 8, 9, 10, 11]
    5 is present: true
    [5, 6, 7, 8, 9, 10, 11, Test]
    5
    [6, 7, 8, 9, 10, 11]
    [1, 2, 3, 4, 5, 6, 7]
    
  • Sextet Class

    Introduction

    The org.javatuples.Sextet class represents a Tuple with six elements.

    Class Declaration

    Following is the declaration for org.javatuples.Sextet class −

    public final class Sextet<A, B, C, D, E, F>
       extends Tuple
    
      implements IValue0&lt;A&gt;, IValue1&lt;B&gt;, 
         IValue2&lt;C&gt;, IValue3&lt;D&gt;, IValue4&lt;E&gt;,
            IValue5&lt;F&gt;

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Class Constructor

    Sr.No.Constructor & Description
    1Sextet(A value0, B value1, C value2, D value3, E value4, F value5)This creates a Sextet Tuple.

    Class Methods

    Similarly setAt1() upto setAt5() set the value at index 1, and so on.

    Sr.No.Method & Description
    1Septet add(Unit tuple)This method returns a Septet tuple.Similarly other methods to add tuples are available e.g. add(Pair tuple) returns Octet and upto add(Quartet tuple) returns Decade tuple.
    2Septet add(X0 value)This method add a value to the tuple and returns a Septet tuple.Similarly other methods to add values are available e.g. add(X0 value0, X1 value1) returns Octet and so on upto add() with four parameters.
    3Septet addAt0(Unit value)This method add a Unit tuple at index 0 and returns a Septet tuple.Similarly other methods to add tuples are available e.g. addAt0(Pair value) returns Octet and so on upto addAt0(Quartet). Other similar method are addAt1(Unit value) which add a unit at index0 and have similar methods upto addAt5(Quartet).
    4Septet addAt0(X0 value)This method add a value at index 0 and returns a Septet tuple.Similarly other methods to add values are available e.g. addAt0(X0 value0, X1 value1) returns Octet and so on upto addAt0() with four parameters. Other similar method are addAt1(X0 value) which add a value at index0 and have similar methods upto addAt5() with four parameters.
    5static <X> Sextet<X,X,X,X,X,X> fromArray(X[] array)Create tuple from array.
    6static <X> Sextet<X,X,X,X,X,X> fromCollection(Collection<X> collection)Create tuple from collection.
    7static <X> Sextet<X,X,X,X,X,X> fromIterable(Iterable<X> iterable)Create tuple from iterable.
    8static <X> Sextet<X,X,X,X,X,X> fromIterable(Iterable<X> iterable, int index)Create tuple from iterable, starting from the specified index.
    9int getSize()Return the size of the tuple.
    10A getValue0()Returns the value of the tuple at index 0.Similarly getValue1() upto getValue5() returns the value at index 1 and so on.
    11Quintet<B,C,D,E,F> removeFrom0()Return the tuple after removing value of the tuple at index 0.Similarly removeFrom1() upto removeFrom5() returns the tuple after removing value of the tuple at index 1 and so on.
    12<X> Sextet<X,B,C,D,E,F> setAt0(X value)Set the value of the tuple at index 0.
    13static <A> Sextet<A,B,C,D,E,F> with(A value0, B value1, C value2, D value3, E value4, F value5)Create the tuple using given value.

    Methods inherite

    This class inherits methods from the following classes −

    • org.javatuples.Tuple
    • Object

    Example

    Let’s see Sextet Class in action. Here we’ll see how to use various methods.

    Create a java class file named TupleTester in C:\>JavaTuples.

    File: TupleTester.java

    package com.tutorialspoint;
    import java.util.ArrayList;
    import java.util.List;
    import org.javatuples.Quartet;
    import org.javatuples.Quintet;
    import org.javatuples.Sextet;
    import org.javatuples.Septet;
    public class TupleTester {
       public static void main(String args[]){
    
      Sextet&lt;Integer, Integer, Integer, Integer, Integer,Integer&gt; sextet 
         = Sextet.with(5, 6, 7,8,9,10);
      System.out.println(sextet);
      boolean isPresent = sextet.contains(5);
      System.out.println("5 is present: " + isPresent);
      List&lt;Integer&gt; list = new ArrayList&lt;&gt;();
      list.add(1);
      list.add(2);
      list.add(3);
      list.add(4);
      list.add(5);
      list.add(6);
      Septet&lt;Integer, Integer, Integer, Integer, Integer, Integer, String&gt; septet 
         = sextet.add("Test");
      System.out.println(septet);
      Integer value = sextet.getValue0();
      System.out.println(value);
      Quintet&lt;Integer, Integer, Integer, Integer,Integer&gt; quintet 
         = sextet.removeFrom0();
      System.out.println(quintet);
      Sextet&lt;Integer, Integer, Integer, Integer, Integer,Integer&gt; sextet1 
         = Sextet.fromCollection(list);   
      System.out.println(sextet1);
    } }

    Verify the result

    Compile the classes using javac compiler as follows −

    C:\JavaTuples>javac -cp javatuples-1.2.jar ./com/tutorialspoint/TupleTester.java
    

    Now run the TupleTester to see the result −

    C:\JavaTuples>java  -cp .;javatuples-1.2.jar com.tutorialspoint.TupleTester
    

    Output

    Verify the Output

    [5, 6, 7, 8, 9, 10]
    5 is present: true
    [5, 6, 7, 8, 9, 10, Test]
    5
    [6, 7, 8, 9, 10]
    [1, 2, 3, 4, 5, 6]
    
  • Quintet Class

    Introduction

    The org.javatuples.Quintet class represents a Tuple with five elements.

    Class Declaration

    Following is the declaration for org.javatuples.Quintet class −

    public final class Quintet<A, B, C, D, E>
       extends Tuple
    
      implements IValue0&lt;A&gt;, IValue1&lt;B&gt;, 
         IValue2&lt;C&gt;, IValue3&lt;D&gt;, IValue4&lt;E&gt;

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Class Constructor

    Sr.No.Constructor & Description
    1Quintet(A value0, B value1, C value2, D value3, E value4)This creates a Quintet Tuple.

    Class Methods

    Similarly setAt1() upto setAt4() set the value at index 1, and so on.

    Sr.No.Method & Description
    1Sextet add(Unit tuple)This method returns a Sextet tuple.Similarly other methods to add tuples are available e.g. add(Pair tuple) returns Septet and upto add(Quintet tuple) returns Decade tuple.
    2Sextet add(X0 value)This method add a value to the tuple and returns a Sextet tuple.Similarly other methods to add values are available e.g. add(X0 value0, X1 value1) returns Septet and so on upto add() with five parameters.
    3Sextet addAt0(Unit value)This method add a Unit tuple at index 0 and returns a Sextet tuple.Similarly other methods to add tuples are available e.g. addAt0(Pair value) returns Septet and so on upto addAt0(Quintet). Other similar method are addAt1(Unit value) which add a unit at index0 and have similar methods upto addAt4(Quintet).
    4Sextet addAt0(X0 value)This method add a value at index 0 and returns a Sextet tuple.Similarly other methods to add values are available e.g. addAt0(X0 value0, X1 value1) returns Septet and so on upto addAt0() with five parameters. Other similar method are addAt1(X0 value) which add a value at index0 and have similar methods upto addAt4() with five parameters.
    5static <X> Quintet<X,X,X,X,X> fromArray(X[] array)Create tuple from array.
    6static <X> Quintet<X,X,X,X,X> fromCollection(Collection<X> collection)Create tuple from collection.
    7static <X> Quintet<X,X,X,X,X> fromIterable(Iterable<X> iterable)Create tuple from iterable.
    8static <X> Quintet<X,X,X,X,X> fromIterable(Iterable<X> iterable, int index)Create tuple from iterable, starting from the specified index.
    9int getSize()Return the size of the tuple.
    10A getValue0()Returns the value of the tuple at index 0.Similarly getValue1() upto getValue4() returns the value at index 1 and so on.
    11Quartet<B,C,D,E> removeFrom0()Return the tuple after removing value of the tuple at index 0.Similarly removeFrom1() upto removeFrom4() returns the tuple after removing value of the tuple at index 1 and so on.
    12<X> Quintet<X,B,C,D,E> setAt0(X value)Set the value of the tuple at index 0.
    13static <A> Quintet<A,B,C,D,E> with(A value0, B value1, C value2, D value3, E value4)Create the tuple using given value.

    Methods inherite

    This class inherits methods from the following classes −

    • org.javatuples.Tuple
    • Object

    Example

    Let’s see Quintet Class in action. Here we’ll see how to use various methods.

    Create a java class file named TupleTester in C:\>JavaTuples.

    File: TupleTester.java

    package com.tutorialspoint;
    import java.util.ArrayList;
    import java.util.List;
    import org.javatuples.Quartet;
    import org.javatuples.Quintet;
    import org.javatuples.Sextet;
    import org.javatuples.Triplet;
    
    public class TupleTester {
       public static void main(String args[]){
    
      Quintet&lt;Integer, Integer, Integer, Integer, Integer&gt; quintet 
         = Quintet.with(5, 6, 7,8,9);
      System.out.println(quintet);
      boolean isPresent = quintet.contains(5);
      System.out.println("5 is present: " + isPresent);
      List&lt;Integer&gt; list = new ArrayList&lt;&gt;();
      list.add(1);
      list.add(2);
      list.add(3);
      list.add(4);
      list.add(5);
      Sextet&lt;Integer, Integer, Integer, Integer, Integer, String&gt; sextet 
         = quintet.add("Test");
      System.out.println(sextet);
      Integer value = quintet.getValue0();
      System.out.println(value);
      Quartet&lt;Integer, Integer, Integer, Integer&gt; quartet = quintet.removeFrom0();
      System.out.println(quartet);
      Quintet&lt;Integer, Integer, Integer, Integer, Integer&gt; quintet1 
         = Quintet.fromCollection(list);   
      System.out.println(quintet1);
    } }

    Verify the result

    Compile the classes using javac compiler as follows −

    C:\JavaTuples>javac -cp javatuples-1.2.jar ./com/tutorialspoint/TupleTester.java
    

    Now run the TupleTester to see the result −

    C:\JavaTuples>java  -cp .;javatuples-1.2.jar com.tutorialspoint.TupleTester
    

    Output

    Verify the Output

    [5, 6, 7, 8, 9]
    5 is present: true
    [5, 6, 7, 8, 9, Test]
    5
    [6, 7, 8, 9]
    [1, 2, 3, 4, 5]
    
  • Quartet Class

    Introduction

    The org.javatuples.Quartet class represents a Tuple with four elements.

    Class Declaration

    Following is the declaration for org.javatuples.Quartet class −

    public final class Quartet<A, B, C, D>
       extends Tuple
    
      implements IValue0&lt;A&gt;, IValue1&lt;B&gt;, IValue2&lt;C&gt;, IValue3&lt;D&gt;

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Class Constructor

    Sr.No.Constructor & Description
    1Quartet(A value0, B value1, C value2, D value3)This creates a Quartet Tuple.

    Class Methods

    Similarly setAt1() upto setAt3() set the value at index 1, and so on.

    Sr.No.Method & Description
    1Quintet add(Unit tuple)This method returns a Quintet tuple.Similarly other methods to add tuples are available e.g. add(Pair tuple) returns Sextet and upto add(Sextet tuple) returns Decade tuple.
    2Quintet add(X0 value)This method add a value to the tuple and returns a Quintet tuple.Similarly other methods to add values are available e.g. add(X0 value0, X1 value1) returns Sextet and so on upto add() with six parameters.
    3Quintet addAt0(Unit value)This method add a Unit tuple at index 0 and returns a Quintet tuple.Similarly other methods to add tuples are available e.g. addAt0(Pair value) returns Sextet and so on upto addAt0(Sextet). Other similar method are addAt1(Unit value) which add a unit at index0 and have similar methods upto addAt2(Sextet).
    4Quintet addAt0(X0 value)This method add a value at index 0 and returns a Quintet tuple.Similarly other methods to add values are available e.g. addAt0(X0 value0, X1 value1) returns Sextet and so on upto addAt0() with six parameters. Other similar method are addAt1(X0 value) which add a value at index0 and have similar methods upto addAt2() with six parameters.
    5static <X> Quartet<X,X,X,X> fromArray(X[] array)Create tuple from array.
    6static <X> Quartet<X,X,X,X> fromCollection(Collection<X> collection)Create tuple from collection.
    7static <X> Quartet<X,X,X,X> fromIterable(Iterable<X> iterable)Create tuple from iterable.
    8static <X> Quartet<X,X,X,X> fromIterable(Iterable<X> iterable, int index)Create tuple from iterable, starting from the specified index.
    9int getSize()Return the size of the tuple.
    10A getValue0()Returns the value of the tuple at index 0.Similarly getValue1() upto getValue3() returns the value at index 1 and so on.
    11Triplet<B,C,D> removeFrom0()Return the tuple after removing value of the tuple at index 0.Similarly removeFrom1() upto removeFrom3() returns the tuple after removing value of the tuple at index 1 and so on.
    12<X> Quartet<X,B,C,D> setAt0(X value)Set the value of the tuple at index 0.
    13static <A> Quartet<A,B,C,D> with(A value0, B value1, C value2, D value3)Create the tuple using given value.

    Methods inherite

    This class inherits methods from the following classes −

    • org.javatuples.Tuple
    • Object

    Example

    Let’s see Quartet Class in action. Here we’ll see how to use various methods.

    Create a java class file named TupleTester in C:\>JavaTuples.

    File: TupleTester.java

    package com.tutorialspoint;
    import java.util.ArrayList;
    import java.util.List;
    import org.javatuples.Quartet;
    import org.javatuples.Quintet;
    import org.javatuples.Triplet;
    
    public class TupleTester {
       public static void main(String args[]){
    
      Quartet&lt;Integer, Integer, Integer, Integer&gt; quartet = Quartet.with(
         5, 6, 7,8
      );
      System.out.println(quartet);
      boolean isPresent = quartet.contains(5);
      System.out.println("5 is present: " + isPresent);
      List&lt;Integer&gt; list = new ArrayList&lt;&gt;();
      list.add(1);
      list.add(2);
      list.add(3);
      list.add(4);
      Quintet&lt;Integer, Integer, Integer, Integer, String&gt; quintet = quartet.add("Test");
      System.out.println(quintet);
      Integer value = quartet.getValue0();
      System.out.println(value);
      Triplet&lt;Integer, Integer, Integer&gt; triplet = quartet.removeFrom0();
      System.out.println(triplet);
      Quartet&lt;Integer, Integer, Integer, Integer&gt; quartet1 = Quartet.fromCollection(list);   
      System.out.println(quartet1);
    } }

    Verify the result

    Compile the classes using javac compiler as follows −

    C:\JavaTuples>javac -cp javatuples-1.2.jar ./com/tutorialspoint/TupleTester.java
    

    Now run the TupleTester to see the result −

    C:\JavaTuples>java  -cp .;javatuples-1.2.jar com.tutorialspoint.TupleTester
    

    Output

    Verify the Output

    [5, 6, 7, 8]
    5 is present: true
    [5, 6, 7, 8, Test]
    5
    [6, 7, 8]
    [1, 2, 3, 4]
    
  • Triplet Class

    Introduction

    The org.javatuples.Triplet class represents a Tuple with three elements.

    Class Declaration

    Following is the declaration for org.javatuples.Triplet class −

    public final class Triplet<A,B,C>
       extends Tuple
    
      implements IValue0&lt;A&gt;, IValue1&lt;B&gt;, IValue2&lt;C&gt;

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Class Constructors

    Sr.No.Constructor & Description
    1Triplet(A value0, B value1, C value2)This creates a Triplet Tuple.

    Class Methods

    Similarly setAt1() upto setAt2() set the value at index 1 and so on.

    Sr.No.Method & Description
    1Quartet add(Unit tuple)This method returns a Quartet tuple.Similarly other methods to add tuples are available e.g. add(Pair tuple) returns Quintet and upto add(Septet tuple) returns Decade tuple.
    2Quartet add(X0 value)This method add a value to the tuple and returns a Quartet tuple.Similarly other methods to add values are available e.g. add(X0 value0, X1 value1) returns Quintet and so on upto add() with seven parameters.
    3Quartet addAt0(Unit value)This method add a Unit tuple at index 0 and returns a Quartet tuple.Similarly other methods to add tuples are available e.g. addAt0(Pair value) returns Quintet and so on upto addAt0(Septet). Other similar method are addAt1(Unit value) which add a unit at index0 and have similar methods upto addAt2(Septet).
    4Quartet addAt0(X0 value)This method add a value at index 0 and returns a Quartet tuple.Similarly other methods to add values are available e.g. addAt0(X0 value0, X1 value1) returns Quintet and so on upto addAt0() with seven parameters. Other similar method are addAt1(X0 value) which add a value at index0 and have similar methods upto addAt2() with seven parameters.
    5static <X> Triplet<X,X,X> fromArray(X[] array)Create tuple from array.
    6static <X> Triplet<X,X,X> fromCollection(Collection<X> collection)Create tuple from collection.
    7static <X> Triplet<X,X,X> fromIterable(Iterable<X> iterable)Create tuple from iterable.
    8static <X> Triplet<X,X,X> fromIterable(Iterable<X> iterable, int index)Create tuple from iterable, starting from the specified index.
    9int getSize()Return the size of the tuple.
    10A getValue0()Returns the value of the tuple at index 0.Similarly getValue1() upto getValue2() returns the value at index 1 and so on.
    11Pair<B,C> removeFrom0()Return the tuple after removing value of the tuple at index 0.Similarly removeFrom1() upto removeFrom2() returns the tuple after removing value of the tuple at index 1 and so on.
    12<X> Triplet<X,B,C> setAt0(X value)Set the value of the tuple at index 0.
    13static <A> Triplet<A,B,C> with(A value0, B value1, C value2)Create the tuple using given value.

    Methods inherite

    This class inherits methods from the following classes −

    • org.javatuples.Tuple
    • Object

    Example

    Let’s see Triplet Class in action. Here we’ll see how to use various methods.

    Create a java class file named TupleTester in C:\>JavaTuples.

    File: TupleTester.java

    package com.tutorialspoint;
    import java.util.ArrayList;
    import java.util.List;
    import org.javatuples.Pair;
    import org.javatuples.Quartet;
    import org.javatuples.Triplet;
    
    public class TupleTester {
       public static void main(String args[]){
    
      Triplet&lt;Integer, Integer, Integer&gt; triplet = Triplet.with(5, 6, 7);
      System.out.println(triplet);
      boolean isPresent = triplet.contains(5);
      System.out.println("5 is present: " + isPresent);
      List&lt;Integer&gt; list = new ArrayList&lt;&gt;();
      list.add(1);
      list.add(2);
      list.add(3);
      Quartet&lt;Integer, Integer, Integer, String&gt; quartet = triplet.add("Test");
      System.out.println(quartet);
      Integer value = triplet.getValue0();
      System.out.println(value);
      Pair&lt;Integer, Integer&gt; pair = triplet.removeFrom0();
      System.out.println(pair);
      Triplet&lt;Integer, Integer, Integer&gt; triplet1 = 
         Triplet.fromCollection(list);   
      System.out.println(triplet1);
    } }

    Verify the result

    Compile the classes using javac compiler as follows −

    C:\JavaTuples>javac -cp javatuples-1.2.jar ./com/tutorialspoint/TupleTester.java
    

    Now run the TupleTester to see the result −

    C:\JavaTuples>java  -cp .;javatuples-1.2.jar com.tutorialspoint.TupleTester
    

    Output

    Verify the Output

    [5, 6, 7]
    5 is present: true
    [5, 6, 7, Test]
    5
    [6, 7]
    [1, 2, 3]
    
  • Pair Class

    Introduction

    The org.javatuples.Pair class represents a Tuple with two elements.

    Class Declaration

    Following is the declaration for org.javatuples.Pair class −

    public final class Pair<A,B>
       extends Tuple
    
      implements IValue0&lt;A&gt;, IValue1&lt;B&gt;

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Class Constructor

    Sr.No.Constructor & Description
    1Pair(A value0, B value1)This creates a Pair Tuple.

    Class Methods

    Similarly setAt1() set the value at index 1.

    Sr.No.Method & Description
    1Triplet add(Unit tuple)This method returns a Triplet tuple.Similarly other methods to add tuples are available e.g. add(Pair tuple) returns Quartet and upto add(Octet tuple) returns Decade tuple.
    2Triplet add(X0 value)This method add a value to the tuple and returns a Triplet tuple.Similarly other methods to add values are available e.g. add(X0 value0, X1 value1) returns Quartet and so on upto add() with eight parameters.
    3Triplet addAt0(Unit value)This method add a Unit tuple at index 0 and returns a Triplet tuple.Similarly other methods to add tuples are available e.g. addAt0(Pair value) returns Quartet and so on upto addAt0(Octet). Other similar method are addAt1(Unit value) which add a unit at index0 and have similar methods upto addAt2(Octet).
    4Triplet addAt0(X0 value)This method add a value at index 0 and returns a Triplet tuple.Similarly other methods to add values are available e.g. addAt0(X0 value0, X1 value1) returns Quartet and so on upto addAt0() with eight parameters. Other similar method are addAt1(X0 value) which add a value at index0 and have similar methods upto addAt2() with eight parameters.
    5static <X> Pair<X,X> fromArray(X[] array)Create tuple from array.
    6static <X> Pair<X,X> fromCollection(Collection<X> collection)Create tuple from collection.
    7static <X> Pair<X,X> fromIterable(Iterable<X> iterable)Create tuple from iterable.
    8static <X> Pair<X,X> fromIterable(Iterable<X> iterable, int index)Create tuple from iterable, starting from the specified index.
    9int getSize()Return the size of the tuple.
    10A getValue0()Returns the value of the tuple at index 0.Similarly getValue1() returns the value at index 1.
    11Unit<B> removeFrom0()Return the tuple after removing value of the tuple at index 0.Similarly removeFrom1() returns the tuple after removing value of the tuple at index 1.
    12<X> Pair<X,B> setAt0(X value)Set the value of the tuple at index 0.
    13static <A,B> Pair<A,B> with(A value0, B value1)Create the tuple using given value.

    Methods inherite

    This class inherits methods from the following classes −

    • org.javatuples.Tuple
    • Object

    Example

    Let’s see Pair Class in action. Here we’ll see how to use various methods.

    Create a java class file named TupleTester in C:\>JavaTuples.

    File: TupleTester.java

    package com.tutorialspoint;
    import java.util.ArrayList;
    import java.util.List;
    import org.javatuples.Pair;
    import org.javatuples.Triplet;
    import org.javatuples.Unit;
    
    public class TupleTester {
       public static void main(String args[]){
    
      Pair&lt;Integer, Integer&gt; pair = Pair.with(5,6);
      System.out.println(pair);
      boolean isPresent = pair.contains(5);
      System.out.println("5 is present: " + isPresent);
      List&lt;Integer&gt; list = new ArrayList&lt;&gt;();
      list.add(1);
      list.add(2);
      Triplet&lt;Integer,Integer, String&gt; triplet = pair.add("Test");
      System.out.println(triplet);
      Integer value = pair.getValue0();
      System.out.println(value);
      Unit&lt;Integer&gt; unit = pair.removeFrom0();
      System.out.println(unit);
      Pair&lt;Integer, Integer&gt; pair1 = Pair.fromCollection(list);   
      System.out.println(pair1);
    } }

    Verify the result

    Compile the classes using javac compiler as follows −

    C:\JavaTuples>javac -cp javatuples-1.2.jar ./com/tutorialspoint/TupleTester.java
    

    Now run the TupleTester to see the result −

    C:\JavaTuples>java  -cp .;javatuples-1.2.jar com.tutorialspoint.TupleTester
    

    Output

    Verify the Output

    [5, 6]
    5 is present: true
    [5, 6, Test]
    5
    [6]
    [1, 2]