JavaTuples中的Triplet类
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]