在 JavaTuples 中设置 Decade 值
要设置 Decade 元组中的新值,你需要使用 setAtX() 方法。这里,X 是你要在其中设置值的索引。例如,setAt2() 在索引 2 处设置值。要包括的值要作为参数中的值设置,如下所示
setAt2(“Amit”);
首先让我们看看在 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]
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP