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
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP