Java LabelValue 元組的 contains() 方法
在 Java 中使用 LabelValue 類的 contains() 方法搜尋值。如果元組中存在該值,則返回 TRUE,否則返回 FALSE 值。
我們首先看看要使用 JavaTuples 需要什麼。要在 JavaTuples 中使用 LabelValue 類,您需要匯入以下包−
import org.javatuples.LabelValue;
注意 − 下載 JavaTuples Jar 庫來執行 JavaTuples 程式。如果您使用 Eclipse IDE,則右擊 專案 -> 屬性 -> Java 構建路徑 -> 新增外部 JAR,並上傳下載的 JavaTuples jar 檔案。請參閱以下指南,瞭解執行 JavaTuples 的所有步驟 −
步驟 − 如何在 Eclipse 中執行 JavaTuples 程式
以下是實現 Java 中 LabelValue 類的 contains() 方法的一個示例 −
示例
import org.javatuples.LabelValue;
public class Demo {
public static void main(String[] args) {
LabelValue<Integer, String> lv = new LabelValue<Integer, String>(5, "Rank");
System.out.println("LabelValue Tuple = "+lv);
System.out.println("Get the key = "+lv.getLabel());
System.out.println("Get the value = "+lv.getValue());
System.out.println("Does the value exist = "+lv.contains(500));
}
}輸出
The following is the output: LabelValue Tuple = [5, Rank] Get the key = 5 Get the value = Rank Does the value exist = false
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP