In a HashMap, we can
Iterating Using the forEach loop.
Output
In the above program, note that we have imported the java.util.Map.Entry package. Here, Map.Entry is the nested class of the Map interface. This nested class returns a view (elements) of the map. It is also possible to iterate a HashMap using the iterator() method. In order to use this method, we must import the java.util.Iterator package.
Output
In the above program, note that we have imported the java.util.Map.Entry package. Here, Map.Entry is the nested class of the Map interface. This nested class returns a view (elements) of the map.