在 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]

更新於: 30-Jul-2019

89 次檢視

開啟你的 職業

透過完成課程獲得認證

立即開始
廣告
© . All rights reserved.