JavaTuples 中 Decade 類是什麼?


Decade 類是一種元組,包含 10 個元素。它在 JavaTuples 庫中。以下是宣告 −

public final class Decade<P, Q, R, S, T, U, V, W, X, Y>
extends Tuple
implements IValue0<P>, IValue1<Q> , IValue2<Q>, IValue3<Q>, IValue4<Q>, IValue5<Q>, IValue6<Q>, IValue7<Q>, IValue8<Q>, IValue9<Q>

讓我們首先了解在 JavaTuples 中工作所需的內容。要在 JavaTuples 中使用 Decade 類,需要匯入以下包: −

import org.javatuples.Decade;

注意 − 下載 JavaTuples Jar 庫來執行 JavaTuples 程式。如果你正在使用 Eclipse IDE,那麼右鍵單擊Project -> Properties -> Java Build Path -> Add External Jar 並上傳下載的 JavaTuples jar 檔案。檢視以下指南,瞭解執行 JavaTuples 的所有步驟 −

步驟如何在 Eclipse 中執行 JavaTuples 程式

以下是 JavaTuples 中 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("Kane","Katie", "Tom","Ryan", "Tom","Bradley", "David","Steve", "Brad", "Jacob");
      System.out.println("Elements in the Decade Tuple = ");
      for (Object ele : d)
         System.out.println(ele);
   }
}

輸出

Elements in the Decade Tuple =
Kane
Katie
Tom
Ryan
Tom
Bradley
David
Steve
Brad
Jacob

上文已建立了包含 10 個字串元素的元組 −

Decade<String, String, String, String, String, String, String, String, String, String> d = Decade.with("Kane","Katie", "Tom","Ryan", "Tom","Bradley", "David","Steve", "Brad", "Jacob");

更新於: 2019-07-30

91 次瀏覽

開啟你的職業

透過完成課程獲得認證

開始吧
廣告
© . All rights reserved.