JavaTuples - Quick Guide



JavaTuples - Overview

Tuple

Tuple is a sequence of objects which may or may not be of same type. Consider the following example −

[12,"TutorialsPoint", java.sql.Connection@li757b]

Above object is a tuple of three elements, an Integer, a string and a Connection Object.

JavaTuple

JavaTuples is a very simple library which offers ten different tuple classses which are sufficient to handle most of the tuple related requirements.

  • Unit<A> - 1 element

  • Pair<A,B> - 2 elements

  • Triplet<A,B,C> - 3 elements

  • Quartet<A,B,C,D> - 4 elements

  • Quintet<A,B,C,D,E> - 5 elements

  • Sextet<A,B,C,D,E,F> - 6 elements

  • Septet<A,B,C,D,E,F,G> - 7 elements

  • Octet<A,B,C,D,E,F,G,H> - 8 elements

  • Ennead<A,B,C,D,E,F,G,H,I> - 9 elements

  • Decade<A,B,C,D,E,F,G,H,I,J> - 10 elements

Apart from these tuple classes, JavaTuples also provides two additional classes for semantics sake.

  • KeyValue<A,B>

  • LabelValue<A,B>

All tuple classes are typesafe and immutable and implements following interfaces and methods.

  • Iterable

  • Serializable

  • Comparable<Tuple>

  • equals()

  • hashCode()

  • toString()

Tuple vs List/Array

List or Array can contain any number of elements but each element must be of same type whereas tuples can contain only specific number of elements, can have different type of elements but still are typesafe.

JavaTuples - Environment Setup

Local Environment Setup

If you are still willing to set up your environment for Java programming language, then this section guides you on how to download and set up Java on your machine. Please follow the steps mentioned below to set up the environment.

Java SE is freely available from the link Download Java. So you download a version based on your operating system.

Follow the instructions to download Java and run the .exe to install Java on your machine. Once you have installed Java on your machine, you would need to set environment variables to point to correct installation directories −

Setting up the Path for Windows 2000/XP

We are assuming that you have installed Java in c:\Program Files\java\jdk directory −

  • Right-click on 'My Computer' and select 'Properties'.

  • Click on the 'Environment variables' button under the 'Advanced' tab.

  • Now, alter the 'Path' variable so that it also contains the path to the Java executable. Example, if the path is currently set to 'C:\WINDOWS\SYSTEM32', then change your path to read 'C:\WINDOWS\SYSTEM32;c:\Program Files\java\jdk\bin'.

Setting up the Path for Windows 95/98/M

We are assuming that you have installed Java in c:\Program Files\java\jdk directory −

  • Edit the 'C:\autoexec.bat' file and add the following line at the end − 'SET PATH=%PATH%;C:\Program Files\java\jdk\bin'

Setting up the Path for Linux, UNIX, Solaris, FreeBS

Environment variable PATH should be set to point to where the Java binaries have been installed. Refer to your shell documentation if you have trouble doing this.

Example, if you use bash as your shell, then you would add the following line to the end of your '.bashrc: export PATH=/path/to/java:$PATH'

Popular Java Editor

To write your Java programs, you need a text editor. There are many sophisticated IDEs available in the market. But for now, you can consider one of the following −

  • Notepad − On Windows machine you can use any simple text editor like Notepad (Recommended for this tutorial), TextPad.

  • Netbeans − It is a Java IDE that is open-source and free which can be downloaded from www.netbeans.org/index.html.

  • Eclipse − It is also a Java IDE developed by the eclipse open-source community and can be downloaded from www.eclipse.org.

Download JavaTuples Archie

Download the latest version of JavaTuples jar file from Maven Repository - JavaTuples. In this tutorial, javatuples-1.2.jar is downloaded and copied into C:\> javatuples folder.

OS Archive name
Windows javatuples-1.2.jar
Linux javatuples-1.2.jar
Mac javatuples-1.2.jar

Set JavaTuples Environment

Set the JavaTuples environment variable to point to the base directory location where JavaTuples jar is stored on your machine. Assuming, we've extracted javatuples-1.2.jar in JavaTuples folder on various Operating Systems as follows.

OS Output
Windows Set the environment variable JavaTuples to C:\JavaTuples
Linux export JavaTuples=/usr/local/JavaTuples
Mac export JavaTuples=/Library/JavaTuples

Set CLASSPATH Variable

Set the CLASSPATH environment variable to point to the JavaTuples jar location. Assuming, you have stored javatuples-1.2.jar in JavaTuples folder on various Operating Systems as follows.

OS Output
Windows Set the environment variable CLASSPATH to %CLASSPATH%;%JavaTuples%\javatuples-1.2.jar;.;
Linux export CLASSPATH=$CLASSPATH:$JavaTuples/javatuples-1.2.jar:.
Mac export CLASSPATH=$CLASSPATH:$JavaTuples/javatuples-1.2.jar:.

JavaTuples - Create Tuples

A tuple using JavaTuple classes can be created using multiple options. Following are the examples −

Using with() Methods

Each tuple class has a with() method with corresponding parameters. For example −

Pair<String, Integer> pair = Pair.with("Test", Integer.valueOf(5));
Triplet<String, Integer, Double> triplet = Triplet.with("Test", Integer.valueOf(5), 
   Double.valueOf(32.1));	

Using Constructor

Each tuple class has a constructor with corresponding parameters. For example −

Pair<String, Integer> pair = new Pair("Test", Integer.valueOf(5));
Triplet<String, Integer, Double> triplet = new Triplet("Test", Integer.valueOf(5), 
   Double.valueOf(32.1));	

Using Collections

Each tuple class has a fromCollection() method with corresponding parameters. For example −

Pair<String, Integer> pair = Pair.fromCollection(listOfTwoElements);	

Using Iterable

Each tuple class has a fromIterable() method to get elements in generic fashion. For example −

// Retrieve three values from an iterable starting at index 5
Triplet<Integer,Integer,Integer> triplet = Triplet.fromIterable(listOfInts, 5);

Example

Let's see JavaTuples in action. Here we'll see how to create tupels using various ways.

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;

public class TupleTester {
   public static void main(String args[]){
      //Create using with() method
      Pair<String, Integer> pair = Pair.with("Test", Integer.valueOf(5));   
      //Create using constructor()
      Pair<String, Integer> pair1 = new Pair("Test", Integer.valueOf(5)); 
      List<Integer> listOfInts = new ArrayList<Integer>();
      listOfInts.add(1);
      listOfInts.add(2);
      //Create using fromCollection() method
      Pair<Integer, Integer> pair2 = Pair.fromCollection(listOfInts);	  
      listOfInts.add(3);
      listOfInts.add(4);
      listOfInts.add(5);
      listOfInts.add(6);
      listOfInts.add(8);
      listOfInts.add(9);
      listOfInts.add(10);
      listOfInts.add(11);
      //Create using fromIterable() method
      // Retrieve three values from an iterable starting at index 5
      Pair<Integer,Integer> pair3 = Pair.fromIterable(listOfInts, 5);
      //print all tuples
      System.out.println(pair);
      System.out.println(pair1);
      System.out.println(pair2);
      System.out.println(pair3);
   }
}

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

[Test, 5]
[Test, 5]
[1, 2]
[6, 8]

JavaTuples - Get Values

A tuple has getValueX() methods to get values and getValue() a generic method to get value by index. For example Triplet class has following methods.

  • getValue(index) − returns value at index starting from 0.

  • getValue0() − returns value at index 0.

  • getValue1() − returns value at index 1.

  • getValue2() − returns value at index 2.

Feature

  • getValueX() methods are typesafe and no cast is required, but getValue(index) is generic.

  • A tuple has getValueX() methods upto element count. For example, Triplet has no getValue3() method but Quartet has.

  • Semantic Classes KeyValue and LabelValue has getKey()/getValue() and getLabel()/getValue() instead of getValue0()/getValue1() methods.

Example

Let's see JavaTuples in action. Here we'll see how to get values from a tuple using various ways.

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

File: TupleTester.java

package com.tutorialspoint;
import org.javatuples.KeyValue;
import org.javatuples.Pair;
public class TupleTester {
   public static void main(String args[]){
      //Create using with() method
      Pair<String, Integer> pair = Pair.with("Test", Integer.valueOf(5));   
      Object value0Obj = pair.getValue(0);
      Object value1Obj = pair.getValue(1);
      String value0 = pair.getValue0();
      Integer value1 = pair.getValue1();
      System.out.println(value0Obj);
      System.out.println(value1Obj);
      System.out.println(value0);
      System.out.println(value1);  
	   KeyValue<String, Integer> keyValue = KeyValue.with(
         "Test", Integer.valueOf(5)
      );
      value0 = keyValue.getKey();
      value1 = keyValue.getValue();
      System.out.println(value0Obj);
      System.out.println(value1Obj);
   }
}

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

Test
5
Test
5
Test
5

JavaTuples - Set Values

A tuple has setAtX() methods to set value at particular index. For example Triplet class has following methods.

  • setAt0() − set value at index 0.

  • setAt1() − set value at index 1.

  • setAt2() − set value at index 2.

Feature

  • Tuples are immutable. Each setAtX() returns a new tuple which is to be used to see the updated value.

  • Type of a position of a tuple can be changed using setAtX() method.

Example

Let's see JavaTuples in action. Here we'll see how to set values in a tuple using various ways.

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

File: TupleTester.java

package com.tutorialspoint;
import org.javatuples.Pair;
public class TupleTester {
   public static void main(String args[]){
      //Create using with() method
      Pair<String, Integer> pair = Pair.with("Test", Integer.valueOf(5));   
      Pair<String, Integer> pair1 = pair.setAt0("Updated Value");
      System.out.println("Original Pair: " + pair);
      System.out.println("Updated Pair:" + pair1);
      Pair<String, String> pair2 = pair.setAt1("Changed Type");
      System.out.println("Original Pair: " + pair);
      System.out.println("Changed Pair:" + pair2);
   }
}

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

Original Pair: [Test, 5]
Updated Pair:[Updated Value, 5]
Original Pair: [Test, 5]
Changed Pair:[Test, Changed Type]

JavaTuples - Add Elements

A tuple has add() method at the end of a tuple and it changes the type of tuple as well. For example adding a element to Triplet tuple will convert it to a Quartet tuple.

Quartet<String,String,String,String> quartet = triplet.add("Test");

A tuple has addAtX() methods as well to add a position at particular index starting from 0.

Quartet<String,String,String,String> quartet = triplet.addAt1("Test");

A tuple can add more than one elements using addAtX() methods.

Quartet<String,String,String,String> quartet = pair.addAt1("Test1", "Test2");

A tuple can add a tuple as well using addAtX() methods.

Quartet<String,String,String,String> quartet = pair.addAt1(pair1);

Example

Let's see JavaTuples in action. Here we'll see how to add values in a tuple using various ways.

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

File: TupleTester.java

package com.tutorialspoint;
import org.javatuples.Pair;
import org.javatuples.Quartet;
import org.javatuples.Quintet;
import org.javatuples.Triplet;
public class TupleTester {
   public static void main(String args[]){
      Pair<String, Integer> pair = Pair.with("Test", Integer.valueOf(5));   
      Triplet<String, Integer, String> triplet = pair.add("Test2");
      Quartet<String, String, Integer, String> quartet = triplet.addAt1("Test1");
      Quintet<String, Integer, String, String, Integer> quintet = triplet.add(pair);
      System.out.println("Pair: " + pair);
      System.out.println("Triplet:" + triplet);
      System.out.println("Quartet:" + quartet);
      System.out.println("Quintet:" + quintet);     
   }
}

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

Pair: [Test, 5]
Triplet:[Test, 5, Test2]
Quartet:[Test, Test1, 5, Test2]
Quintet:[Test, 5, Test2, Test, 5]

JavaTuples - Remove Elements

A tuple has removeAtX() methods to remove value at particular index. For example Triplet class has following methods.

  • removeAt0() − remove value at index 0 and return the resulted tuple.

  • removeAt1() − remove value at index 1 and return the resulted tuple.

  • removeAt2() − remove value at index 2 and return the resulted tuple.

Removing an element returns a new tuple.

Example

Let's see JavaTuples in action. Here we'll see how to remove value in a tuple.

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

File: TupleTester.java

package com.tutorialspoint;
import org.javatuples.Pair;
import org.javatuples.Triplet;
public class TupleTester {
   public static void main(String args[]){
      Triplet<String, Integer, String> triplet = Triplet.with(
         "Test1", Integer.valueOf(5), "Test2"
      );
      Pair<String, Integer> pair = triplet.removeFrom2();
      System.out.println("Triplet:" + triplet);
      System.out.println("Pair: " + pair);  
   }
}

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

Triplet:[Test1, 5, Test2]
Pair: [Test1, 5]

JavaTuples - Conversion

Tuple to List/Array

A tuple can be converted to List/Array but at cost of type safety and converted list is of type List<Object>/Object[].

List<Object> list = triplet.toList();
Object[] array = triplet.toArray();

Collection/Array to Tuple

A collection can be converted to tuple using fromCollection() method and array can be converted to tuple using fromArray() method.

Pair<String, Integer> pair = Pair.fromCollection(list);
Quartet<String,String,String,String> quartet = Quartet.fromArray(array); 

If size of array/collection is different than that of tuple, then IllegalArgumentException will occur.

Exception in thread "main" java.lang.IllegalArgumentException: 
Array must have exactly 4 elements in order to create a Quartet. Size is 5
   at ...	

Example

Let's see JavaTuples in action. Here we'll see how to convert tuple to list/array and vice versa.

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

File: TupleTester.java

package com.tutorialspoint;
import java.util.List;
import org.javatuples.Quartet;
import org.javatuples.Triplet;
public class TupleTester {
   public static void main(String args[]){
      Triplet<String, Integer, String> triplet = Triplet.with(
         "Test1", Integer.valueOf(5), "Test2"
      );
      List<Object> list = triplet.toList();
      Object[] array = triplet.toArray();
      System.out.println("Triplet:" + triplet);
      System.out.println("List: " + list);  
      System.out.println();
      for(Object object: array) {
         System.out.print(object + " " );
      }
      System.out.println();
      String[] strArray = new String[] {"a", "b" , "c" , "d"};
      Quartet<String, String, String, String> quartet = Quartet.fromArray(strArray);
      System.out.println("Quartet:" + quartet);      
   }
}

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

Triplet:[Test1, 5, Test2]
List: [Test1, 5, Test2]

Test1 5 Test2 
Quartet:[a, b, c, d]

JavaTuples - Iteration

Each tuple implements Iterable interface and can be iterated in similar fashion as collection.

Pair<String, Integer> pair = Pair.with("Test", Integer.valueOf(5)); 
for(Object object: Pair){
	System.out.println(object);
}

Example

Let's see JavaTuples in action. Here we'll see how to iterate tuples.

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<String, Integer, String> triplet = Triplet.with(
         "Test1", Integer.valueOf(5), "Test2"
      );
      for(Object object: triplet) {
         System.out.print(object + " " );
      }
      System.out.println();
      System.out.println(triplet);
      String[] strArray = new String[] {"a", "b" , "c" , "d"};
      Quartet<String, String, String, String> quartet = Quartet.fromArray(strArray);
      for(Object object: quartet) {
         System.out.print(object + " " );
      }
      System.out.println();
      System.out.println("Quartet:" + quartet);
   }
}

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

Test1 5 Test2 
[Test1, 5, Test2]
a b c d 
Quartet:[a, b, c, d]

JavaTuples - Checking Elements

Each tuple provides utility methods to check their elements in similar fashion as collection.

  • contains(element) − checks if element is present or not.

  • containsAll(collection) − checks if elements are present or not.

  • indexOf(element) − returns the index of first element if present otherwise -1.

  • lastIndexOf(element) − returns the index of last element if present otherwise -1.

Pair<String, Integer> pair = Pair.with("Test", Integer.valueOf(5)); 
boolean isPresent = pair.contains("Test");

Example

Let's see JavaTuples in action. Here we'll see how to check elements in a tuple.

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

File: TupleTester.java

package com.tutorialspoint;
import java.util.List;
import org.javatuples.Quartet;
public class TupleTester {
   public static void main(String args[]){
      Quartet<String, Integer, String, String> quartet = Quartet.with(
         "Test1", Integer.valueOf(5), "Test3", "Test3"
      );
      System.out.println(quartet);
      boolean isPresent = quartet.contains(5);
      System.out.println("5 is present: " + isPresent);
      isPresent = quartet.containsAll(List.of("Test1", "Test3"));   
      System.out.println("Test1, Test3 are present: " + isPresent);
      int indexOfTest3 = quartet.indexOf("Test3");
      System.out.println("First Test3 is present at: " + indexOfTest3);
      int lastIndexOfTest3 = quartet.lastIndexOf("Test3");
      System.out.println("Last Test3 is present at: " + lastIndexOfTest3);
   }
}

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

[Test1, 5, Test3, Test3]
5 is present: true
Test1, Test3 are present: true
First Test3 is present at: 2
Last Test3 is present at: 3

JavaTuples - Unit Class

Introduction

The org.javatuples.Unit class represents a Tuple with single element.

Class declaration

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

public final class Unit<A>
   extends Tuple
      implements IValue0<A>

Class constructors

Sr.No. Constructor & Description
1

Unit(A value0)

This creates a Unit Tuple.

Class Methods

Sr.No. Method & Description
1

Pair add(Unit tuple)

This method returns a Pair tuple.

Similarly other methods to add tuples are available e.g. add(Pair tuple) returns Triplet and upto add(Ennead tuple) returns Decade tuple.

2

Pair add(X0 value)

This method add a value to the tuple and returns a Pair tuple.

Similarly other methods to add values are available e.g. add(X0 value0, X1 value1) returns Triplet and so on upto add() with nine parameters.

3

Pair addAt0(Unit value)

This method add a Unit tuple at index 0 and returns a Pair tuple.

Similarly other methods to add tuples are available e.g. addAt0(Pair value) returns Triplet and so on upto addAt0(Ennead). Other similar method are addAt1(Unit value) which add a unit at index0 and have similar methods upto addAt1(Ennead).

4

Pair addAt0(X0 value)

This method add a value at index 0 and returns a Pair tuple.

Similarly other methods to add values are available e.g. addAt0(X0 value0, X1 value1) returns Triplet and so on upto addAt0() with nine parameters. Other similar method are addAt1(X0 value) which add a value at index0 and have similar methods upto addAt1() with nine parameters.

5

static <X> Unit<X> fromArray(X[] array)

Create tuple from array.

6

static <X> Unit<X> fromCollection(Collection<X> collection)

Create tuple from collection.

7

static <X> Unit<X> fromIterable(Iterable<X> iterable)

Create tuple from iterable.

8

static <X> Unit<X> fromIterable(Iterable<X> iterable, int index)

Create tuple from iterable, starting from the specified index.

9

int getSize()

Return the size of the tuple.

10

A getValue0()

Return the value of the tuple.

11

<X> Unit<X> setAt0(X value)

Set the value of the tuple.

12

static <A> Unit<A> with(A value0)

Create the tuple using given value.

Methods inherite

This class inherits methods from the following classes −

  • org.javatuples.Tuple

  • Object

Example

Let's see Unit 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.Unit;
public class TupleTester {
   public static void main(String args[]){
      Unit<Integer> unit = Unit.with(5);
      System.out.println(unit);
      boolean isPresent = unit.contains(5);
      System.out.println("5 is present: " + isPresent);
      List<Integer> list = new ArrayList<>();
      list.add(1);
      Pair<Integer, String> pair = unit.add("Test");
      System.out.println(pair);
      Integer value = unit.getValue0();
      System.out.println(value);
      Unit<Integer> unit1 = Unit.fromCollection(list);   
      System.out.println(unit1);
   }
}

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]
5 is present: true
[5, Test]
5
[1]

JavaTuples - 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<A>, IValue1<B>

Class Constructor

Sr.No. Constructor & Description
1

Pair(A value0, B value1)

This creates a Pair Tuple.

Class Methods

Similarly setAt1() set the value at index 1.

Sr.No. Method & Description
1

Triplet 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.

2

Triplet 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.

3

Triplet 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).

4

Triplet 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.

5

static <X> Pair<X,X> fromArray(X[] array)

Create tuple from array.

6

static <X> Pair<X,X> fromCollection(Collection<X> collection)

Create tuple from collection.

7

static <X> Pair<X,X> fromIterable(Iterable<X> iterable)

Create tuple from iterable.

8

static <X> Pair<X,X> fromIterable(Iterable<X> iterable, int index)

Create tuple from iterable, starting from the specified index.

9

int getSize()

Return the size of the tuple.

10

A getValue0()

Returns the value of the tuple at index 0.

Similarly getValue1() returns the value at index 1.

11

Unit<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.

13

static <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<Integer, Integer> pair = Pair.with(5,6);
      System.out.println(pair);
      boolean isPresent = pair.contains(5);
      System.out.println("5 is present: " + isPresent);
      List<Integer> list = new ArrayList<>();
      list.add(1);
      list.add(2);
      Triplet<Integer,Integer, String> triplet = pair.add("Test");
      System.out.println(triplet);
      Integer value = pair.getValue0();
      System.out.println(value);
      Unit<Integer> unit = pair.removeFrom0();
      System.out.println(unit);
      Pair<Integer, Integer> 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]

JavaTuples - 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<A>, IValue1<B>, IValue2<C>

Class Constructors

Sr.No. Constructor & Description
1

Triplet(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
1

Quartet 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.

2

Quartet 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.

3

Quartet 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).

4

Quartet 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.

5

static <X> Triplet<X,X,X> fromArray(X[] array)

Create tuple from array.

6

static <X> Triplet<X,X,X> fromCollection(Collection<X> collection)

Create tuple from collection.

7

static <X> Triplet<X,X,X> fromIterable(Iterable<X> iterable)

Create tuple from iterable.

8

static <X> Triplet<X,X,X> fromIterable(Iterable<X> iterable, int index)

Create tuple from iterable, starting from the specified index.

9

int getSize()

Return the size of the tuple.

10

A getValue0()

Returns the value of the tuple at index 0.

Similarly getValue1() upto getValue2() returns the value at index 1 and so on.

11

Pair<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.

13

static <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<Integer, Integer, Integer> triplet = Triplet.with(5, 6, 7);
      System.out.println(triplet);
      boolean isPresent = triplet.contains(5);
      System.out.println("5 is present: " + isPresent);
      List<Integer> list = new ArrayList<>();
      list.add(1);
      list.add(2);
      list.add(3);
      Quartet<Integer, Integer, Integer, String> quartet = triplet.add("Test");
      System.out.println(quartet);
      Integer value = triplet.getValue0();
      System.out.println(value);
      Pair<Integer, Integer> pair = triplet.removeFrom0();
      System.out.println(pair);
      Triplet<Integer, Integer, Integer> 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]

JavaTuples - 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<A>, IValue1<B>, IValue2<C>, IValue3<D>

Class Constructor

Sr.No. Constructor & Description
1

Quartet(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
1

Quintet 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.

2

Quintet 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.

3

Quintet 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).

4

Quintet 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.

5

static <X> Quartet<X,X,X,X> fromArray(X[] array)

Create tuple from array.

6

static <X> Quartet<X,X,X,X> fromCollection(Collection<X> collection)

Create tuple from collection.

7

static <X> Quartet<X,X,X,X> fromIterable(Iterable<X> iterable)

Create tuple from iterable.

8

static <X> Quartet<X,X,X,X> fromIterable(Iterable<X> iterable, int index)

Create tuple from iterable, starting from the specified index.

9

int getSize()

Return the size of the tuple.

10

A getValue0()

Returns the value of the tuple at index 0.

Similarly getValue1() upto getValue3() returns the value at index 1 and so on.

11

Triplet<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.

13

static <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<Integer, Integer, Integer, Integer> quartet = Quartet.with(
         5, 6, 7,8
      );
      System.out.println(quartet);
      boolean isPresent = quartet.contains(5);
      System.out.println("5 is present: " + isPresent);
      List<Integer> list = new ArrayList<>();
      list.add(1);
      list.add(2);
      list.add(3);
      list.add(4);
      Quintet<Integer, Integer, Integer, Integer, String> quintet = quartet.add("Test");
      System.out.println(quintet);
      Integer value = quartet.getValue0();
      System.out.println(value);
      Triplet<Integer, Integer, Integer> triplet = quartet.removeFrom0();
      System.out.println(triplet);
      Quartet<Integer, Integer, Integer, Integer> 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]

JavaTuples - 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<A>, IValue1<B>, 
         IValue2<C>, IValue3<D>, IValue4<E>

Class Constructor

Sr.No. Constructor & Description
1

Quintet(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
1

Sextet 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.

2

Sextet 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.

3

Sextet 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).

4

Sextet 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.

5

static <X> Quintet<X,X,X,X,X> fromArray(X[] array)

Create tuple from array.

6

static <X> Quintet<X,X,X,X,X> fromCollection(Collection<X> collection)

Create tuple from collection.

7

static <X> Quintet<X,X,X,X,X> fromIterable(Iterable<X> iterable)

Create tuple from iterable.

8

static <X> Quintet<X,X,X,X,X> fromIterable(Iterable<X> iterable, int index)

Create tuple from iterable, starting from the specified index.

9

int getSize()

Return the size of the tuple.

10

A getValue0()

Returns the value of the tuple at index 0.

Similarly getValue1() upto getValue4() returns the value at index 1 and so on.

11

Quartet<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.

13

static <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<Integer, Integer, Integer, Integer, Integer> 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<Integer> list = new ArrayList<>();
      list.add(1);
      list.add(2);
      list.add(3);
      list.add(4);
      list.add(5);
      Sextet<Integer, Integer, Integer, Integer, Integer, String> sextet 
         = quintet.add("Test");
      System.out.println(sextet);
      Integer value = quintet.getValue0();
      System.out.println(value);
      Quartet<Integer, Integer, Integer, Integer> quartet = quintet.removeFrom0();
      System.out.println(quartet);
      Quintet<Integer, Integer, Integer, Integer, Integer> 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]

JavaTuples - 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<A>, IValue1<B>, 
         IValue2<C>, IValue3<D>, IValue4<E>,
            IValue5<F>

Class Constructor

Sr.No. Constructor & Description
1

Sextet(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
1

Septet 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.

2

Septet 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.

3

Septet 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).

4

Septet 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.

5

static <X> Sextet<X,X,X,X,X,X> fromArray(X[] array)

Create tuple from array.

6

static <X> Sextet<X,X,X,X,X,X> fromCollection(Collection<X> collection)

Create tuple from collection.

7

static <X> Sextet<X,X,X,X,X,X> fromIterable(Iterable<X> iterable)

Create tuple from iterable.

8

static <X> Sextet<X,X,X,X,X,X> fromIterable(Iterable<X> iterable, int index)

Create tuple from iterable, starting from the specified index.

9

int getSize()

Return the size of the tuple.

10

A getValue0()

Returns the value of the tuple at index 0.

Similarly getValue1() upto getValue5() returns the value at index 1 and so on.

11

Quintet<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.

13

static <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<Integer, Integer, Integer, Integer, Integer,Integer> 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<Integer> list = new ArrayList<>();
      list.add(1);
      list.add(2);
      list.add(3);
      list.add(4);
      list.add(5);
      list.add(6);
      Septet<Integer, Integer, Integer, Integer, Integer, Integer, String> septet 
         = sextet.add("Test");
      System.out.println(septet);
      Integer value = sextet.getValue0();
      System.out.println(value);
      Quintet<Integer, Integer, Integer, Integer,Integer> quintet 
         = sextet.removeFrom0();
      System.out.println(quintet);
      Sextet<Integer, Integer, Integer, Integer, Integer,Integer> 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]

JavaTuples - 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<A>, IValue1<B>, 
         IValue2<C>, IValue3<D>, IValue4<E>,
            IValue5<F>, IValue6<G>

Class Constructor

Sr.No. Constructor & Description
1

Septet(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
1

Octet 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.

2

Octet 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.

3

Octet 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).

4

Octet 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.

5

static <X> Septet<X,X,X,X,X,X,X> fromArray(X[] array)

Create tuple from array.

6

static <X> Septet<X,X,X,X,X,X,X> fromCollection(Collection<X> collection)

Create tuple from collection.

7

static <X> Septet<X,X,X,X,X,X,X> fromIterable(Iterable<X> iterable)

Create tuple from iterable.

8

static <X> Septet<X,X,X,X,X,X,X> fromIterable(Iterable<X> iterable, int index)

Create tuple from iterable, starting from the specified index.

9

int getSize()

Return the size of the tuple.

10

A getValue0()

Returns the value of the tuple at index 0.

Similarly getValue1() upto getValue6() returns the value at index 1 and so on.

11

Sextet<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.

13

static <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<Integer, Integer, Integer, Integer, Integer,Integer,Integer> 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<Integer> list = new ArrayList<>();
      list.add(1);
      list.add(2);
      list.add(3);
      list.add(4);
      list.add(5);
      list.add(6);
      list.add(7);
      Octet<Integer, Integer, Integer, Integer, Integer, Integer, Integer, String> octet 
         = septet.add("Test");
      System.out.println(octet);
      Integer value = septet.getValue0();
      System.out.println(value);
      Sextet<Integer, Integer, Integer, Integer,Integer, Integer> sextet 
         = septet.removeFrom0();
      System.out.println(sextet);
      Septet<Integer, Integer, Integer, Integer, Integer,Integer, Integer> 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]

JavaTuples - 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<A>, IValue1<B>, 
         IValue2<C>, IValue3<D>, IValue4<E>,
            IValue5<F>, IValue6<G>, IValue7<H>

Class Constructor

Sr.No. Constructor & Description
1

Octet(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
1

Ennead add(Unit tuple)

This method returns a Ennead tuple.

Similarly other methods to add tuples are available e.g. add(Pair tuple) returns Decade.

2

Ennead 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.

3

Ennead 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).

4

Ennead 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.

5

static <X> Octet<X,X,X,X,X,X,X,X> fromArray(X[] array)

Create tuple from array.

6

static <X> Octet<X,X,X,X,X,X,X,X> fromCollection(Collection<X> collection)

Create tuple from collection.

7

static <X> Octet<X,X,X,X,X,X,X,X> fromIterable(Iterable<X> iterable)

Create tuple from iterable.

8

static <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.

9

int getSize()

Return the size of the tuple.

10

A getValue0()

Returns the value of the tuple at index 0.

Similarly getValue1() upto getValue7() returns the value at index 1 and so on.

11

Septet<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.

13

static <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<Integer, Integer, Integer, Integer, Integer,Integer,Integer,Integer>
      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<Integer> list = new ArrayList<>();
      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<Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, String>
      ennead = octet.add("Test");
      System.out.println(ennead);
      Integer value = octet.getValue0();
      System.out.println(value);
      Septet<Integer, Integer, Integer, Integer,Integer, Integer,Integer>
      septet = octet.removeFrom0();
      System.out.println(septet);
      Octet<Integer, Integer, Integer, Integer, Integer,Integer, Integer, Integer> 
      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]

JavaTuples - 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<A>, IValue1<B>, 
         IValue2<C>, IValue3<D>, IValue4<E>,
            IValue5<F>, IValue6<G>, IValue7<H>,
               IValue8<I>

Class Constructor

Sr.No. Constructor & Description
1

Ennead(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
1

Decade add(Unit tuple)

This method returns a Decade tuple.

2

Decade add(X0 value)

This method add a value to the tuple and returns a Decade tuple.

3

Decade 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).

4

Decade 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.

5

static <X> Ennead<X,X,X,X,X,X,X,X,X > fromArray(X[] array)

Create tuple from array.

6

static <X> Ennead<X,X,X,X,X,X,X,X,X> fromCollection(Collection<X> collection)

Create tuple from collection.

7

static <X> Ennead<X,X,X,X,X,X,X,X,X> fromIterable(Iterable<X> iterable)

Create tuple from iterable.

8

static <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.

9

int getSize()

Return the size of the tuple.

10

A getValue0()

Returns the value of the tuple at index 0.

Similarly getValue1() upto getValue8() returns the value at index 1 and so on.

11

Octet<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.

13

static <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<Integer, Integer, Integer, Integer, Integer,
         Integer,Integer,Integer, Integer> 
      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<Integer> list = new ArrayList<>();
      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<Integer, Integer, Integer, Integer, Integer, 
         Integer, Integer, Integer, Integer, String> decade = ennead.add("Test");
      System.out.println(decade);
      Integer value = ennead.getValue0();
      System.out.println(value);
      Octet<Integer, Integer, Integer, Integer,Integer, 
         Integer,Integer, Integer> octet = ennead.removeFrom0();
      System.out.println(octet);
      Ennead<Integer, Integer, Integer, Integer, Integer,
         Integer, Integer, Integer,Integer> 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]

JavaTuples - 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<A>, IValue1<B>, 
         IValue2<C>, IValue3<D>, IValue4<E>,
            IValue5<F>, IValue6<G>, IValue7<H>,
               IValue8<I>, IValue9<J>

Class Constructor

Sr.No. Constructor & Description
1

Decade(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
1

static <X> Decade<X,X,X,X,X,X,X,X,X,X > fromArray(X[] array)

Create tuple from array.

2

static <X> Decade<X,X,X,X,X,X,X,X,X,X> fromCollection(Collection<X> collection)

Create tuple from collection.

3

static <X> Decade<X,X,X,X,X,X,X,X,X,X> fromIterable(Iterable<X> iterable)

Create tuple from iterable.

4

static <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.

5

int getSize()

Return the size of the tuple.

6

A getValue0()

Returns the value of the tuple at index 0.

Similarly getValue1() upto getValue9() returns the value at index 1 and so on.

7

Ennead<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.

9

static <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<Integer, Integer, Integer, Integer, 
         Integer,Integer,Integer,Integer, Integer, Integer> 
      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<Integer> list = new ArrayList<>();
      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<Integer, Integer, Integer, Integer,Integer, 
         Integer,Integer, Integer, Integer> ennead = decade.removeFrom0();
      System.out.println(ennead);
      Decade<Integer, Integer, Integer, Integer, Integer,
         Integer, Integer, Integer,Integer, Integer> 
         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]

JavaTuples - 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<A>, IValue1<B>

Class Constructor

Sr.No. Constructor & Description
1

LabelValue(A value0, B value1)

This creates a LabelValue Tuple.

Class Methods

Sr.No. Method & Description
1

static <X> LabelValue<X,X> fromArray(X[] array)

Create tuple from array.

2

static <X> LabelValue<X,X> fromCollection(Collection<X> collection)

Create tuple from collection.

3

static <X> LabelValue<X,X> fromIterable(Iterable<X> iterable)

Create tuple from iterable.

4

static <X> LabelValue<X,X> fromIterable(Iterable<X> iterable, int index)

Create tuple from iterable, starting from the specified index.

5

A getLabel()

Return the label.

6

int getSize()

Return the size of the tuple.

7

A 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.

10

static <A,B> LabelValue<A,B> with(A value0, B value1)

Create the tuple using given value.

Methods inherits

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<Integer, Integer> labelValue = LabelValue.with(5,6);
      System.out.println(labelValue);
      List<Integer> list = new ArrayList<>();
      list.add(1);
      list.add(2);
      Integer label = labelValue.getLabel();
      System.out.println(label);
      Integer value = labelValue.getValue();
      System.out.println(value);
      LabelValue<Integer, Integer> 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]

JavaTuples - 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<A>, IValue1<B>

Class Constructor

Sr.No. Constructor & Description
1

KeyValue(A value0, B value1)

This creates a KeyValue Tuple.

Class Methods

Sr.No. Method & Description
1

static <X> KeyValue<X,X> fromArray(X[] array)

Create tuple from array.

2

static <X> KeyValue<X,X> fromCollection(Collection<X> collection)

Create tuple from collection.

3

static <X> KeyValue<X,X> fromIterable(Iterable<X> iterable)

Create tuple from iterable.

4

static <X> KeyValue<X,X> fromIterable(Iterable<X> iterable, int index)

Create tuple from iterable, starting from the specified index.

5

A getKey()

Return the key.

6

int getSize()

Return the size of the tuple.

7

A 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.

10

static <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<Integer, Integer> keyValue = KeyValue.with(5,6);
      System.out.println(keyValue);
      List<Integer> list = new ArrayList<>();
      list.add(1);
      list.add(2);
      Integer key = KeyValue.getKey();
      System.out.println(key);
      Integer value = KeyValue.getValue();
      System.out.println(value);
      KeyValue<Integer, Integer> 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]

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

Output

Verify the Output

[5]
[5, test]
[test, 5]

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

Output

Verify the Output

[5, 6]
[5, 6, test]
[test, 5, 6]

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

Output

Verify the Output

[5, 6, 7]
[5, 6, 7, test]
[test, 5, 6, 7]

Implementing Quintet Using Quartet Class

Problem Description

How to implement Quintet class using Quartet 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.Quintet;
import org.javatuples.Quartet;
public class TupleTester {
   public static void main(String args[]){
      Quartet<Integer, Integer, Integer, Integer> quartet = Quartet.with(5,6,7,8);
      System.out.println(quartet);
      Quintet<Integer, Integer, Integer, Integer, String> quintet = quartet.add("test");
      Quintet<String, Integer, Integer, Integer, Integer> quintet1 = quartet.addAt0("test");
      System.out.println(quintet);
      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]
[5, 6, 7, 8, test]
[test, 5, 6, 7, 8]

Implementing Sextet Using Quintet Class

Problem Description

How to implement Sextet class using Quintet 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.Quintet;
import org.javatuples.Sextet;
public class TupleTester {
   public static void main(String args[]){
      Quintet<Integer, Integer, Integer, Integer, Integer> quintet 
         = Quintet.with(5,6,7,8,9);
      System.out.println(quintet);
      Sextet<Integer, Integer, Integer, Integer, Integer, String> sextet 
         = quintet.add("test");
      Sextet<String, Integer, Integer, Integer, Integer, Integer> sextet1 
         = quintet.addAt0("test");
      System.out.println(sextet);
      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]
[5, 6, 7, 8, 9, test]
[test, 5, 6, 7, 8, 9]

Implementing Septet using Sextet Class

Problem Description

How to implement Septet class using Sextet 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.Septet;
import org.javatuples.Sextet;
public class TupleTester {
   public static void main(String args[]){
      Sextet<Integer, Integer, Integer, Integer, Integer, Integer> sextet 
         = Sextet.with(5,6,7,8,9,10);
      System.out.println(sextet);
      Septet<Integer, Integer, Integer, Integer, Integer, Integer, String> 
         septet = sextet.add("test");
      Septet<String, Integer, Integer, Integer, Integer, Integer, Integer> 
         septet1 = sextet.addAt0("test");
      System.out.println(septet);
      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]
[5, 6, 7, 8, 9, 10, test]
[test, 5, 6, 7, 8, 9, 10]

Implementing Octet using Septet Class

Problem Description

How to implement Octet class using Septet 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.Octet;
import org.javatuples.Septet;
public class TupleTester {
   public static void main(String args[]){
      Septet<Integer, Integer, Integer, Integer, Integer, Integer,
         Integer> septet = Septet.with(5,6,7,8,9,10,11);
      System.out.println(septet);
      Octet<Integer, Integer, Integer, Integer, Integer, Integer, 
         Integer, String> octet = septet.add("test");
      Octet<String, Integer, Integer, Integer, Integer, Integer, 
         Integer, Integer> octet1 = septet.addAt0("test");
      System.out.println(octet);
      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]
[5, 6, 7, 8, 9, 10, 11, test]
[test, 5, 6, 7, 8, 9, 10, 11]

Implementing Ennead Using Octet Class

Problem Description

How to implement Ennead class using Octet 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.Ennead;
import org.javatuples.Octet;
public class TupleTester {
   public static void main(String args[]){
      Octet<Integer, Integer, Integer, Integer, Integer, Integer,
         Integer, Integer> octet = Octet.with(5,6,7,8,9,10,11,12);
      System.out.println(octet);
      Ennead<Integer, Integer, Integer, Integer, Integer, Integer, 
         Integer, Integer, String> ennead = octet.add("test");
      Ennead<String, Integer, Integer, Integer, Integer, Integer, 
         Integer, Integer, Integer> ennead1 = octet.addAt0("test");
      System.out.println(ennead);
      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]
[5, 6, 7, 8, 9, 10, 11, 12, test]
[test, 5, 6, 7, 8, 9, 10, 11, 12]

Implementing Decade Using Ennead Class

Problem Description

How to implement Decade class using Ennead 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.Decade;
import org.javatuples.Ennead;
public class TupleTester {
   public static void main(String args[]){
      Ennead<Integer, Integer, Integer, Integer, Integer, Integer,
         Integer, Integer, Integer> ennead = Ennead.with(5,6,7,8,9,10,11,12,13);
      System.out.println(ennead);
      Decade<Integer, Integer, Integer, Integer, Integer, Integer, 
         Integer, Integer, Integer, String> decade = ennead.add("test");
      
      Decade<String, Integer, Integer, Integer, Integer, Integer, 
         Integer, Integer, Integer, Integer> decade1 = ennead.addAt0("test");
      
      System.out.println(decade);
      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]
[5, 6, 7, 8, 9, 10, 11, 12, 13, test]
[test, 5, 6, 7, 8, 9, 10, 11, 12, 13]
Advertisements