在 Java LabelValue 元組中搜索某個值
要在 Java 中搜索 LabelValue 元組中的某個值,請使用 contains() 方法。它返回一個布林值。如果存在該值,則返回 TRUE,否則返回 FALSE。讓我們先了解如何使用 JavaTuples。要使用 JavaTuples 中的 LabelValue 類,需要匯入以下包 −
import org.javatuples.LabelValue;
注意 − 下載 JavaTuples Jar 庫以執行 JavaTuples 程式。如果你使用的是 Eclipse IDE,請右鍵單擊Project -> Properties -> Java Build Path -> Add External Jars 並上傳下載的 JavaTuples jar 檔案。參閱以下指南瞭解執行 JavaTuples 的所有步驟 −
步驟 − 如何在 Eclipse 中執行 JavaTuples 程式
以下是一個在 Java LabelValue 元組中搜索值的示例 −
示例
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("Get the size of the Tuple = "+lv.getSize());
System.out.println("Does the value exist = "+lv.contains("Rank"));
}
}輸出
LabelValue Tuple = [5, Rank] Get the key = 5 Get the value = Rank Get the size of the Tuple = 2 Does the value exist = true
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP