使用 Java 中的“with()”方法建立 Decade 元組
若要使用 Java 建立 Decade 元組,您可以使用“with()”方法。我們首先了解一下使用 JavaTuples 時需要了解的內容。要在 JavaTuples 中使用 Decade 類,您需要匯入以下軟體包。
import org.javatuples.Decade;
注意:下載 JavaTuples Jar 庫來執行 JavaTuples 程式。如果您使用的是 Eclipse IDE,請右鍵單擊專案 → 屬性 → Java 構建路徑 → 新增外部 JAR,然後上傳下載的 JavaTuples JAR 檔案。參考以下指南,瞭解執行 JavaTuples 的所有步驟。
步驟: 如何在 Eclipse 中執行 JavaTuples 程式
以下是使用“with()”方法在 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 = ");
for (Object ele : d)
System.out.println(ele);
}
}輸出
Elements in the Decade Tuple = AB CD EF GH IJ KL MN OP QR ST
在上面,我們使用“with()”方法建立了一個包含 10 個字串元素的元組。
Decade<String, String, String, String, String, String, String, String, String, String> d =
Decade.with("AB","CD", "EF","GH", "IJ","KL", "MN","OP", "QR", "ST");
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP