JavaTuples 中 Decade 类是什么?
Decade 类是一种元组,包含 10 个元素。它在 JavaTuples 库中。以下是声明 −
public final class Decade<P, Q, R, S, T, U, V, W, X, Y> extends Tuple implements IValue0<P>, IValue1<Q> , IValue2<Q>, IValue3<Q>, IValue4<Q>, IValue5<Q>, IValue6<Q>, IValue7<Q>, IValue8<Q>, IValue9<Q>
让我们首先了解在 JavaTuples 中工作所需的内容。要在 JavaTuples 中使用 Decade 类,需要导入以下包: −
import org.javatuples.Decade;
注意 − 下载 JavaTuples Jar 库来运行 JavaTuples 程序。如果你正在使用 Eclipse IDE,那么右键单击Project -> Properties -> Java Build Path -> Add External Jar 并上传下载的 JavaTuples jar 文件。查看以下指南,了解运行 JavaTuples 的所有步骤 −
步骤 − 如何在 Eclipse 中运行 JavaTuples 程序
以下是 JavaTuples 中 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("Kane","Katie", "Tom","Ryan", "Tom","Bradley", "David","Steve", "Brad", "Jacob"); System.out.println("Elements in the Decade Tuple = "); for (Object ele : d) System.out.println(ele); } }
输出
Elements in the Decade Tuple = Kane Katie Tom Ryan Tom Bradley David Steve Brad Jacob
上文已创建了包含 10 个字符串元素的元组 −
Decade<String, String, String, String, String, String, String, String, String, String> d = Decade.with("Kane","Katie", "Tom","Ryan", "Tom","Bradley", "David","Steve", "Brad", "Jacob");
广告