Java ConcurrentSkipListMap containsKey()方法及示例

Java ConcurrentSkipListMap containsKey()方法及示例

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

语法

public boolean containsKey(Object ob)

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

返回值: 如果该地图包含指定键的映射,该函数返回true。

下面的程序说明了上述方法。

程序1:

// Java Program Demonstrate containsKey()
// method of ConcurrentSkipListMap
  
import java.util.concurrent.*;
  
class GFG {
    public static void main(String[] args)
    {
  
        // Initializing the map
        ConcurrentSkipListMap<Integer, Integer>
            mpp = new ConcurrentSkipListMap<Integer,
                                            Integer>();
  
        // Adding elements to this map
        for (int i = 1; i <= 5; i++)
            mpp.put(i, i);
  
        // Checks if 9 is present in the map
        if (mpp.containsKey(9))
            System.out.println("9 is present"
                               + " in the mpp.");
        else
            System.out.println("9 is not present"
                               + " in the mpp.");
    }
}

程序2

// Java Program Demonstrate containsKey()
// method of ConcurrentSkipListMap
  
import java.util.concurrent.*;
  
class GFG {
    public static void main(String[] args)
    {
  
        // Initializing the map
        ConcurrentSkipListMap<Integer, Integer>
            mpp = new ConcurrentSkipListMap<Integer,
                                            Integer>();
  
        // Adding elements to this map
        for (int i = 1; i <= 5; i++)
            mpp.put(i, i);
  
        // Checks if 4 is present in the map
        if (mpp.containsKey(4))
            System.out.println("4 is present"
                               + " in the mpp.");
        else
            System.out.println("4 is not present"
                               + " in the mpp.");
    }
}

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

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程