从 JavaTuples 中的 Triplet 类获取值
java 8object oriented programmingprogramming更新于 2025/4/28 21:22:17
getValueX() 方法用于从 Java 中特定索引处的 Triplet Tuple 类获取值。例如,getValue0()。
首先让我们看看使用 JavaTuples 需要什么。要使用 JavaTuples 中的 Triplet 类,您需要导入以下包 −
import org.javatuples.Triplet;
注意 − 下载和运行 JavaTuples 程序的步骤。如果您使用 Eclipse IDE 在 JavaTuples 中运行 Triplet 类,则右键单击项目 → 属性 → Java 构建路径 → 添加外部 Jar并上传下载的 JavaTuples jar 文件。
下面是一个例子 −
示例
import org.javatuples.Triplet; public class Demo { public static void main(String[] args) { Triplet < String, String, String > t = Triplet.with("Movies", "Web Series", "TV Shows"); System.out.println(t); System.out.println("Get Value: " + t.getValue0()); } }
输出
[Movies, Web Series, TV Shows] Get Value: Movies