Java 中 Decade Tuple 的 setAtX() 方法
setAtX() 方法用于在 Decade Tuple 中设置新值。此处,X 为要设置值的下标。例如,setAt5() 在下标 5 处设置值。要包括的值应作为参数值进行设置,如
setAt5(“Katie”);
让我们首先看看需要做什么来使用 JavaTuples。要使用 JavaTuples 中的 Decade 类,您需要导入以下包
import org.javatuples.Decade;
注意:下载 JavaTuples Jar 库来运行 JavaTuples 程序。如果您使用 Eclipse IDE,则右键单击项目 -> 属性 -> Java 构建路径 -> 添加外部 Jar,然后上传下载的 JavaTuples jar 文件。请参阅以下指南,了解运行 JavaTuples 的所有步骤
步骤: 如何在 Eclipse 中运行 JavaTuples 程序
以下是在 Java 中设置 Decade 值的示例
示例
import org.javatuples.Decade;
public class Demo {
public static void main(String[] args) {
// Tuple with 10 elements
Decade<String, String, String, String, String, String, String, String, String, String> d =
Decade.with("AB","CD", "EF","GH", "IJ","KL", "MN","OP", "QR", "ST");
System.out.println("Elements in the Decade Tuple = ");
Decade<String, String, String, String, String, String, String, String, String, String> d2 = d.setAt6("UV");
System.out.println("Updated Tuple = "+d2);
}
}输出
Elements in the Decade Tuple = Updated Tuple = [AB, CD, EF, GH, IJ, KL, UV, OP, QR, ST]
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP