当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java ConcurrentSkipListMap containsKey()用法及代码示例


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

用法:

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-



相关用法


注:本文由纯净天空筛选整理自Twinkl Bajaj大神的英文原创作品 ConcurrentSkipListMap containsKey() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。