從另一個 Java 集合中建立 Decade 元組
在 Java 中從另一個集合建立 Decade 元組,使用 fromArray() 或 fromCollection() 方法。此處,我們將瞭解如何使用 fromCollection() 方法建立 Decade 元組。此方法允許我們在 Java 中從 List 集合建立 Decade 元組。
我們先了解一下使用 JavaTuples 所需的工作。要在 JavaTuples 中使用 Decade 類,需要匯入以下包
import org.javatuples.Decade;
注意 下載 JavaTuples Jar 庫以執行 JavaTuples 程式。如果你使用 Eclipse IDE,請右鍵
單擊 Project -> Properties -> Java Build Path -> Add External Jars 並上傳下載的 JavaTuples jar 檔案。參考以下指南獲取執行 JavaTuples 的所有步驟
步驟 − 如何在 Eclipse 中執行 JavaTuples 程式
以下是在 Java 中從 List 集合建立 Decade 元組的示例
示例
import java.util.List;
import org.javatuples.Decade;
import java.util.*;
public class Demo {
public static void main(String[] args) {
// 10 elements in the List
List<String> myList = new ArrayList<String> ();
myList.add("Football");
myList.add("Cricket");
myList.add("Tennis");
myList.add("Hockey");
myList.add("Badminton");
myList.add("Archery");
myList.add("Billiards");
myList.add("Cycling");
myList.add("Handball");
myList.add("Squash");
// creating Decade Tuple from List
Decade<String, String, String, String, String, String, String, String, String, String> d = Decade.fromCollection(myList);
System.out.println("Elements in the Decade Tuple = ");
for (Object ele : d)
System.out.println(ele);
}
}輸出
Elements in the Decade Tuple = Football Cricket Tennis Hockey Badminton Archery Billiards Cycling Handball Squash
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP