Java KeyValue 元组的 contains() 方法
使用 contains() 方法搜索 KeyValue 元组中的值。首先,我们来看看使用 JavaTuples 需要做些什么。要在 JavaTuples 中使用 KeyValue 类,需要导入以下包。
import org.javatuples.KeyValue;
注意 下载 JavaTuples Jar 库以运行 JavaTuples 程序。如果你使用的是 Eclipse IDE,则右键单击项目 -> 属性 -> Java 构建路径 -> 添加外部 Jar 并上传下载的 JavaTuples jar 文件。有关运行 JavaTuples 的所有步骤,请参考以下指南。
步骤: 如何在 Eclipse 中运行 JavaTuples 程序
以下是一个示例,在 Java 中实现 KeyValue 元组的 contains() 方法。
示例
import org.javatuples.KeyValue;
public class Demo {
public static void main(String[] args) {
KeyValue<Integer, String> kValue = KeyValue.with(77, "Rank");
System.out.println("Key-Value in the KeyValue Tuple = "+kValue);
boolean res = kValue.contains("Rank");
System.out.println("Does the value exist in the Tuple? = "+res);
}
}输出
Key-Value in the KeyValue Tuple = [77, Rank] Does the value exist in the Tuple? = true
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP