當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。