📌  相关文章
📜  Java中的 ConcurrentSkipListMap containsKey() 方法及示例

📅  最后修改于: 2022-05-13 01:55:07.213000             🧑  作者: Mango

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

Java .util.concurrent.ConcurrentSkipListMapcontainsKey()方法是Java中的一个内置函数,如果此映射中存在指定元素,则返回 true 布尔值,否则返回 false。

句法:

public boolean containsKey(Object ob)

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

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

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

方案一:

// Java Program Demonstrate containsKey()
// 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);
  
        // 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.");
    }
}

方案二:

// Java Program Demonstrate containsKey()
// 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);
  
        // 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-