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