java.util.TreeMap.containsValue() 方法
描述
containsValue(Object value) 方法用于在此映射将一个或多个键映射到指定值时返回 true。
声明
以下是 java.util.TreeMap.containsValue() 方法的声明。
public boolean containsValue(Object value)
参数
value − 这是要在此映射中测试其存在的值。
返回值
如果到此值的映射存在,则方法调用返回 true,否则返回 false。
异常
NA
示例
下面的例子展示了 java.util.TreeMap.containsValue() 方法的使用。
package com.tutorialspoint;
import java.util.*;
public class TreeMapDemo {
public static void main(String[] args) {
// creating tree map
NavigableMap<Integer, String> treemap = new TreeMap<Integer, String>();
// populating tree map
treemap.put(2, "two");
treemap.put(1, "one");
treemap.put(3, "three");
treemap.put(6, "six");
treemap.put(5, "five");
System.out.println("Checking value");
System.out.println("'three' exists: "+ treemap.containsValue("three"));
}
}
让我们编译并运行上面的程序,这将产生以下结果.
Checking value 'three' exists: true

