📜  hashmap 键检查 - 任何代码示例

📅  最后修改于: 2022-03-11 14:55:59.994000             🧑  作者: Mango

代码示例1
// Java code to illustrate the containsKey() method
import java.util.*;
  
public class Hash_Map_Demo {
    public static void main(String[] args)
    {
  
        // Creating an empty HashMap
        HashMap hash_map = new HashMap();
  
        // Mapping string values to int keys
        hash_map.put(10, "Geeks");
        hash_map.put(15, "4");
        hash_map.put(20, "Geeks");
        hash_map.put(25, "Welcomes");
        hash_map.put(30, "You");
  
        // Displaying the HashMap
        System.out.println("Initial Mappings are: " + hash_map);
  
        // Checking for the key_element '20'
        System.out.println("Is the key '20' present? " + 
        hash_map.containsKey(20));
  
        // Checking for the key_element '5'
        System.out.println("Is the key '5' present? " + 
        hash_map.containsKey(5));
    }
}