从另一个 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