

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Triplet Class in JavaTuples
A Triplet class is a Tuple of three elements. It is part of the JavaTuples library.
To work with Triplet class in JavaTuples, you need to import the following package −
import org.javatuples.Triplet;
Example
Let us see an example to implement the Triplet class −
import org.javatuples.Triplet; public class Demo { public static void main(String[] args) { Triplet < String, String, String > t = new Triplet < String, String, String > ("One", "Two", "Three","Four", "Five"); System.out.println(t); } }
Output
[One, Two, Three, Four, Five]
Example
Let us see another example to get value from Triplet class −
import org.javatuples.Triplet; public class Demo { public static void main(String[] args) { Triplet < String, String, String > t = new Triplet < String, String, String > ("One", "Two", "Three","Four", "Five"); System.out.println(t); System.out.println("Get Value: " + t.getValue0()); } }
Output
[One, Two, Three, Four, Five] Get Value: One
Example
Let us see another example to set the Triplet value in JavaTuples and a copy with a new value at the 1st index −
import org.javatuples.Triplet; public class Demo { public static void main(String[] args) { Triplet < String, String, String > t1 = Triplet.with("Movies", "Web Series", "TV Shows"); System.out.println(t1); Triplet < String, String, String > t2 = t1.setAt1("Songs"); System.out.println(t2); } }
Output
[Movies, Web Series, TV Shows] [Movies, Songs, TV Shows]
- Related Questions & Answers
- Iterate through Triplet class in JavaTuples
- JavaTuples addAtX() method for Triplet class
- JavaTuples setAt1() method for Triplet class
- JavaTuples setAt0() method for Triplet class
- Search a value in JavaTuples Triplet class
- The contains() method of Triplet class in JavaTuples
- Add a value to Triplet class in JavaTuples
- Get a value from Triplet class in JavaTuples
- Implement Triplet Class with Pair Class in Java using JavaTuples
- Implement Quartet Class with Triplet Class in Java using JavaTuples
- Iterate through Septet class in JavaTuples
- Iterate through Quartet class in JavaTuples
- What is LabelValue class in JavaTuples?
- What is Decade class in JavaTuples?
- What is KeyValue class in JavaTuples?
Advertisements