fork download
  1. import java.util.*;
  2.  
  3. class Hash_Map_Demo {
  4. public static void main(String[] args)
  5. {
  6.  
  7. // Creating an empty HashMap
  8. HashMap<Integer, String> hash_map = new HashMap<Integer, String>();
  9.  
  10. // Mapping string values to int keys
  11. hash_map.put(10, "Geeks");
  12. hash_map.put(15, "4");
  13. hash_map.put(20, "Geeks");
  14. hash_map.put(25, "Welcomes");
  15. hash_map.put(30, "You");
  16.  
  17. // Displaying the HashMap
  18. System.out.println("Initial Mappings are: " + hash_map);
  19.  
  20. // Getting the value of 25
  21. System.out.println("The Value is: " + hash_map.get(35));
  22.  
  23. // Getting the value of 10
  24. System.out.println("The Value is: " + hash_map.get(10));
  25. }
  26. }
Success #stdin #stdout 0.13s 40896KB
stdin
Standard input is empty
stdout
Initial Mappings are: {20=Geeks, 25=Welcomes, 10=Geeks, 30=You, 15=4}
The Value is: null
The Value is: Geeks