Java中的ConcurrentSkipListMap containsKey()方法及示例

Java中的ConcurrentSkipListMap containsKey()方法及示例

java.util.concurrent.ConcurrentSkipListMap 中的 containsKey() 方法是Java中的内置函数,如果在地图中存在指定的元素,则返回一个真实的布尔值,否则返回false。

语法:

public boolean containsKey(Object ob)

参数: 该函数接受一个单一的必需参数 ob ,指定要测试在该地图中的键的存在。

返回值: 如果该地图包含指定key的映射,则返回true。

以下程序说明了上述方法:

程序1:

// Java程序演示containsKey()
//方法ConcurrentSkipListMap
  
import java.util.concurrent.*;
  
class GFG {
    public static void main(String[] args)
    {
  
        // 初始化地图
        ConcurrentSkipListMap<Integer, Integer>
            mpp = new ConcurrentSkipListMap<Integer, Integer>();
  
        // 向该地图添加元素
        for (int i = 1; i <= 5; i++)
            mpp.put(i, i);
  
        // 检查9是否存在于地图中
        if (mpp.containsKey(9))
            System.out.println("9存在于mpp中。");
        else
            System.out.println("9不存在于mpp中。");
    }
}

程序2:

// Java程序演示containsKey()
//方法ConcurrentSkipListMap
  
import java.util.concurrent.*;
  
class GFG {
    public static void main(String[] args)
    {
  
        // 初始化地图
        ConcurrentSkipListMap<Integer, Integer>
            mpp = new ConcurrentSkipListMap<Integer, Integer>();
  
        // 向该地图添加元素
        for (int i = 1; i <= 5; i++)
            mpp.put(i, i);
  
        // 检查4是否存在于地图中
        if (mpp.containsKey(4))
            System.out.println("4存在于mpp中。");
        else
            System.out.println("4不存在于mpp中。");
    }
}

参考: https://docs.oracle.com/javase/9/docs/api/java/util/concurrent/ConcurrentSkipListMap.html#containsKey-java.lang.Object-

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程