Java Decade Tuple 的 contains() 方法
contains() 方法用于在 Decade Tuple 中搜索一个值。让我们首先了解一下,使用 JavaTuples 需要做哪些准备。要使用 JavaTuples 中的 Decade 类,需要导入以下包
import org.javatuples.Decade;
注意下载 JavaTuples jar 库以运行 JavaTuples 程序。如果你使用的是 Eclipse IDE,则右键单击项目->属性->Java 构建路径->添加外部 jar,然后上传下载的 JavaTuples jar 文件。参阅下面的指南,了解运行 JavaTuples 所需的所有步骤
步骤: 如何在 Eclipse 中运行 JavaTuples 程序
下面是一个示例,演示如何实现 Java Decade Tuple 的 contains() 方法
示例
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 = "+d); boolean res1 = d.contains("MN"); System.out.println("Does the value exist in the Decade Tuple? = "+res1); boolean res2 = d.contains("YZ"); System.out.println("Does the value exist in the Decade Tuple? = "+res2); boolean res3 = d.contains("QR"); System.out.println("Does the value exist in the Decade Tuple? = "+res3); } }
输出
Elements in the Decade Tuple = [AB, CD, EF, GH, IJ, KL, MN, OP, QR, ST] Does the value exist in the Decade Tuple? = true Does the value exist in the Decade Tuple? = false Does the value exist in the Decade Tuple? = true
广告