Implementing Quintet Using Quartet Class

Implementing Quintet Using Quartet Class

This topic is about 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.Adglob;
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/Adglob/TupleTester.java

Now run the TupleTester to see the result −

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

Output

Verify the Output

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

In this topic we learned about Implementing Quintet Using Quartet Class. To know more, Click Here.

This Post Has One Comment

Leave a Reply