boolean containsValue(Object value)
描述 (Description)
如果此映射将一个或多个键映射到指定值,则containsValue(Object value)方法用于返回true。
声明 (Declaration)
以下是java.util.TreeMap.containsValue()方法的声明。
public boolean containsValue(Object value)
参数 (Parameters)
value - 这是要测试其在此映射中的存在的值。
返回值 (Return Value)
如果存在到此值的映射,则方法调用返回true,否则返回false。
异常 (Exception)
NA
例子 (Example)
以下示例显示了java.util.TreeMap.containsValue()方法的用法。
package com.iowiki;
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