在 Java Pair 元组中搜索值
使用 contains() 方法在 JavaTuples Pair 类中搜索值。
让我们先了解在 JavaTuples 中工作时需要什么。要在 JavaTuples 中使用 Pair 类,需要导入以下包 −
import org.javatuples.Pair;
注意 − 下载并运行 JavaTuples 程序的步骤如果使用 Eclipse IDE 在 JavaTuples 中运行 Pair 类,则右键单击**项目 → 属性 → Java 构建路径 → 添加外部 JAR**并上传下载的 JavaTuples jar 文件。
以下是一个示例 −
示例
import org.javatuples.Pair;
public class Demo {
public static void main(String[] args) {
Pair < String, String > p = Pair.with("Mobile", "Desktop");
System.out.println("Pair = " + p);
boolean res = p.contains("Mobile");
System.out.println("Is the value in Tuple? = " + res);
}
}输出
Pair = [Mobile, Desktop] Is the value in Tuple? = true
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
编程
C++
C#
MongoDB
MySQL
JavaScript
PHP