Java Tuple 的 setAt0() 方法適用於 Pair 類
setAt0() 方法用於在 JavaTuples 中設定 Pair 值以及在此處在指定索引(即索引為 0)設定新值的副本。
首先,讓我們瞭解使用 JavaTuples 需要知道哪些內容。要在 JavaTuples 中使用 Pair 類,需匯入以下包 −
import org.javatuples.Pair;
注意 − 下載並執行 JavaTuples 程式的步驟。如果你使用 Eclipse IDE 在 JavaTuples 中執行 Pair 類,則右鍵單擊 專案 → 屬性 → Java 構建路徑 → 新增外部 JAR 並上傳下載的 JavaTuples jar 檔案。
以下是一個示例 −
示例
import org.javatuples.Pair;
public class Demo {
public static void main(String[] args) {
Pair < String, String > p1 = Pair.with("One", "Two");
Pair < String, String > p2 = p1.setAt0("Three");
System.out.println("Result = " + p2);
}
}輸出
Result = [Three, Two]
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP