Source of Hash_Map_Demo.java


  1: //Hash_Map_Demo.java
  2: //From the Geeks for Geeks website

  4: import java.util.HashMap;

  6: public class Hash_Map_Demo
  7: {
  8:     public static void main(String[] args)
  9:     {

 11:         // Creating an empty HashMap
 12:         HashMap<Integer, String> hash_map = new HashMap<Integer, String>();

 14:         // Mapping string values to int keys
 15:         hash_map.put(10, "Geeks");
 16:         hash_map.put(15, "4");
 17:         hash_map.put(20, "Geeks");
 18:         hash_map.put(25, "Welcomes");
 19:         hash_map.put(30, "You");

 21:         // Displaying the HashMap
 22:         System.out.println("Initial Mappings are: " + hash_map);

 24:         // Using values() to get the Collection view of values
 25:         System.out.println("The collection is: " + hash_map.values());
 26:     }
 27: }