Java中的 ConcurrentSkipListMap containsValue() 方法及示例
Java .util.concurrent.ConcurrentSkipListMap的containsValue()方法是Java中的一个内置函数,如果此映射将一个或多个键映射到指定值,则返回true 。如果没有要映射的键,则该方法返回 null。当指定值为 null 时,该方法会抛出 NullPointerException。
句法:
public boolean containsValue(Object ob)
参数:该函数接受一个强制参数ob ,它指定要测试其存在的值。
返回值:如果映射存在则函数返回true,否则返回false。
异常:当指定值为 null 时,该方法抛出 NullPointerException。
下面的程序说明了上述方法:
方案一:
Java
// Java Program Demonstrate containsValue()
// method of ConcurrentSkipListMap
import java.util.concurrent.*;
class GFG {
public static void main(String[] args)
{
// Initializing the map
ConcurrentSkipListMap
mpp = new ConcurrentSkipListMap();
// Adding elements to this map
for (int i = 1; i <= 5; i++)
mpp.put(i, i);
// checking whether object present in map
System.out.println(mpp.containsValue(4));
}
}
Java
// Java Program Demonstrate containsValue()
// method of ConcurrentSkipListMap
import java.util.concurrent.*;
class GFG {
public static void main(String[] args)
{
// Initializing the map
ConcurrentSkipListMap
mpp = new ConcurrentSkipListMap();
// Adding elements to this map
for (int i = 1; i <= 5; i++)
mpp.put(i, i);
// checking whether object present in map
System.out.println(mpp.containsValue(7));
}
}
输出:
true
程序 :
Java
// Java Program Demonstrate containsValue()
// method of ConcurrentSkipListMap
import java.util.concurrent.*;
class GFG {
public static void main(String[] args)
{
// Initializing the map
ConcurrentSkipListMap
mpp = new ConcurrentSkipListMap();
// Adding elements to this map
for (int i = 1; i <= 5; i++)
mpp.put(i, i);
// checking whether object present in map
System.out.println(mpp.containsValue(7));
}
}
输出:
false
参考: https: Java/util/concurrent/ConcurrentSkipListMap.html#containsValue-java.lang.Object-