JavaTuples Tutorial
Selected Reading
- JavaTuples - Discussion
- JavaTuples - Useful Resources
- JavaTuples - Quick Guide
- JavaTuples - Decade using Ennead
- JavaTuples - Ennead using Octet
- JavaTuples - Octet using Septet
- JavaTuples - Septet using Sextet
- JavaTuples - Sextet using Quintet
- JavaTuples - Quintet using Quartet
- JavaTuples - Quartet using Triplet
- JavaTuples - Triplet using Pair
- JavaTuples - Pair using Unit
- JavaTuples - KeyValue Class
- JavaTuples - LabelValues Class
- JavaTuples - Decade Class
- JavaTuples - Ennead Class
- JavaTuples - Octet Class
- JavaTuples - Septet Class
- JavaTuples - Sextet Class
- JavaTuples - Quintet Class
- JavaTuples - Quartet Class
- JavaTuples - Triplet Class
- JavaTuples - Pair Class
- JavaTuples - Unit Class
- JavaTuples - Checking Elements
- JavaTuples - Iteration
- JavaTuples - Conversion
- JavaTuples - Remove Elements
- JavaTuples - Add Elements
- JavaTuples - Set Values
- JavaTuples - Get Values
- JavaTuples - Create Tuples
- JavaTuples - Environment Setup
- JavaTuples - Overview
- JavaTuples - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
JavaTuples - Triplet using Pair
Implementing Triplet Using Pair Class
Problem Description
How to implement Triplet class using Pair class?
Example
Following example shows how to accomppsh 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; pubpc class TupleTester { pubpc 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]Advertisements