從 Java 中的陣列建立九元組


若要從陣列建立九元組,請使用 fromArray() 方法。使用此方法,使用 Java 中的陣列建立九元組。

我們首先來看看使用 JavaTuples 需要用到什麼內容。若要在 JavaTuples 中使用九元組類,你需要匯入以下包。

import org.javatuples.Ennead;

注意 下載 JavaTuples Jar 庫以執行 JavaTuples 程式。如果你使用的是 Eclipse IDE,則右鍵單擊專案->屬性->Java 構建路徑->新增外部 Jar 並上傳下載的 JavaTuples jar 檔案。有關執行 JavaTuples 的所有步驟,請參見以下指南。

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

以下是在 Java 中從陣列建立九元組的示例。

示例

import org.javatuples.Ennead;
public class Demo {
   public static void main(String[] args) {
      String[] strArr = {"Accessories", "Shirt", "Trousers", "Furniture", "Smart Wearable Tech", "Smart Home Automation", "Books", "Stationery", "Instrument"};
      Ennead<String, String, String, String, String, String, String, String, String> e = Ennead.fromArray(strArr);
      System.out.println("Elements in the Ennead Tuple = ");
      for (Object ele : e) System.out.println(ele);
   }
}

輸出

Elements in the Ennead Tuple =
Accessories
Shirt
Trousers
Furniture
Smart Wearable Tech
Smart Home Automation
Books
Stationery
Instrument

更新於: 2019 年 7 月 30 日

92 次瀏覽

開啟你的 職業生涯

參加課程,獲得認證

開始
廣告
© . All rights reserved.