एक Triplet क्लास तीन एलिमेंट्स का टपल है। यह JavaTuples लाइब्रेरी का हिस्सा है।
JavaTuples में Triplet क्लास के साथ काम करने के लिए, आपको निम्नलिखित पैकेज इम्पोर्ट करना होगा:
import org.javatuples.Triplet;
उदाहरण
आइए Triplet क्लास को इम्प्लीमेंट करने का एक उदाहरण देखें:
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);
}
}
आउटपुट
[One, Two, Three, Four, Five]
उदाहरण
आइए Triplet क्लास से मान प्राप्त करने का एक और उदाहरण देखें:
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());
}
}
आउटपुट
[One, Two, Three, Four, Five] Get Value: One
उदाहरण
आइए JavaTuples में Triplet मान सेट करने और पहले इंडेक्स पर नए मान के साथ कॉपी का एक और उदाहरण देखें:
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);
}
}
आउटपुट
[Movies, Web Series, TV Shows] [Movies, Songs, TV Shows]