
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
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 Articles
- Iterate through Triplet class in JavaTuples
- JavaTuples setAt1() method for Triplet class
- JavaTuples setAt0() method for Triplet class
- JavaTuples addAtX() 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
- What is LabelValue class in JavaTuples?
- What is Decade class in JavaTuples?
- What is KeyValue class in JavaTuples?
- What is Ennead class in JavaTuples?
- What is Octet class in JavaTuples?

Advertisements