在 Java 中透過其他集合建立 Ennead 元組
要使用其他集合建立 Ennead 元組,請使用 fromCollection() 方法。使用此方法,可使用列表集合建立一個 Ennead 元組。我們首先了解使用 JavaTuples 需要哪些內容。要在 JavaTuples 中使用 Ennead 類,需要匯入以下包。
import org.javatuples.Ennead;
註釋 下載 JavaTuples Jar 庫以執行 JavaTuples 程式。如果您使用的是 Eclipse IDE,請右鍵單擊專案 -> 屬性 -> Java 構建路徑 -> 新增外部 Jar,然後上傳已下載的 JavaTuples jar 檔案。參閱以下指南瞭解執行 JavaTuples 的所有步驟。
步驟: 如何在 Eclipse 中執行 JavaTuples 程式
以下是在 Java 中透過其他集合建立 Ennead 元組的一個示例。
示例
import org.javatuples.Ennead;
import java.util.*;
public class Demo {
public static void main(String[] args) {
List<String> myList = new ArrayList<String>();
myList.add("Accessories");
myList.add("Shirt");
myList.add("Trousers");
myList.add("Furniture");
myList.add("Smart Wearable Tech");
myList.add("Smart Home Automation");
myList.add("Books");
myList.add("Stationery");
myList.add("Instrument");
Ennead<String, String, String, String, String, String, String, String, String> e = Ennead.fromCollection(myList);
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
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP