Author: saqibkhan

  • Implementing Quartet Using Triplet Class

    Problem Description

    How to implement Quartet class using Triplet class?

    Example

    Following example shows how to accomplish the above task. Each tuple has add() and addAtX() methods to convert the tuple.

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

    File: TupleTester.java

    package com.tutorialspoint;
    import org.javatuples.Quartet;
    import org.javatuples.Triplet;
    public class TupleTester {
       public static void main(String args[]){
    
      Triplet<Integer, Integer, Integer> triplet = Triplet.with(5,6,7);
      System.out.println(triplet);
      Quartet<Integer, Integer, Integer, String> quartet = triplet.add("test");
      Quartet<String, Integer, Integer, Integer> quartet1 = triplet.addAt0("test");
      System.out.println(quartet);
      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
    

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

    Output

    Verify the Output

    [5, 6, 7]
    [5, 6, 7, test]
    [test, 5, 6, 7]
  • Implementing Triplet Using Pair Class

    Problem Description

    How to implement Triplet class using Pair class?

    Example

    Following example shows how to accomplish the above task. Each tuple has add() and addAtX() methods to convert the tuple.

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

    File: TupleTester.java

    package com.tutorialspoint;
    import org.javatuples.Triplet;
    import org.javatuples.Pair;
    public class TupleTester {
       public static void main(String args[]){
    
      Pair<Integer, Integer> pair = Pair.with(5,6);
      System.out.println(pair);
      Triplet<Integer, Integer, String> triplet = pair.add("test");
      Triplet<String, Integer, Integer> triplet1 = pair.addAt0("test");
      System.out.println(triplet);
      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
    

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

    Output

    Verify the Output

    [5, 6]
    [5, 6, test]
    [test, 5, 6]
    
  • Implementing Pair Using Unit Class

    Problem Description

    How to implement Pair class using Unit class?

    Example

    Following example shows how to accomplish the above task. Each tuple has add() and addAtX() methods to convert the tuple.

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

    File: TupleTester.java

    package com.tutorialspoint;
    import org.javatuples.Pair;
    import org.javatuples.Unit;
    public class TupleTester {
       public static void main(String args[]){
    
      Unit<Integer> unit = Unit.with(5);
      System.out.println(unit);
      Pair<Integer, String> pair = unit.add("test");
      Pair<String, Integer> pair1 = unit.addAt0("test");
      System.out.println(pair);
      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
    

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

    Output

    Verify the Output

    [5]
    [5, test]
    [test, 5]
    
  • KeyValue Class

    Introduction

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

    Class Declaration

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

    public final class KeyValue<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
    1KeyValue(A value0, B value1)This creates a KeyValue Tuple.

    Class Methods

    Sr.No.Method & Description
    1static <X> KeyValue<X,X> fromArray(X[] array)Create tuple from array.
    2static <X> KeyValue<X,X> fromCollection(Collection<X> collection)Create tuple from collection.
    3static <X> KeyValue<X,X> fromIterable(Iterable<X> iterable)Create tuple from iterable.
    4static <X> KeyValue<X,X> fromIterable(Iterable<X> iterable, int index)Create tuple from iterable, starting from the specified index.
    5A getKey()Return the key.
    6int getSize()Return the size of the tuple.
    7A getValue()Returns the value of the tuple.
    8<X> KeyValue<X,B> setKey(X key)set the label and return the tuple.
    9<X> KeyValue<A,Y> setValue(Y value)set the value and return the tuple.
    10static <A,B> KeyValue<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 KeyValue 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.KeyValue;
    public class TupleTester {
       public static void main(String args[]){
    
      KeyValue&lt;Integer, Integer&gt; keyValue = KeyValue.with(5,6);
      System.out.println(keyValue);
      List&lt;Integer&gt; list = new ArrayList&lt;&gt;();
      list.add(1);
      list.add(2);
      Integer key = KeyValue.getKey();
      System.out.println(key);
      Integer value = KeyValue.getValue();
      System.out.println(value);
      KeyValue&lt;Integer, Integer&gt; keyValue1 = KeyValue.fromCollection(list);   
      System.out.println(keyValue1);
    } }

    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]
  • 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]