Most of the initial developers easily write iteration code to iterate List and Set using for-each concept. Can we write the same to iterate over a map in java. The answer is yes.
Iterate Over a map.
This is most recommended and simple method to iterate map unlike getting the key set and get each value from the map by iterate the key set.
Iterate Over a map.
This is most recommended and simple method to iterate map unlike getting the key set and get each value from the map by iterate the key set.
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
System.out.println("Key::"+ entry.getKey()+ "::Value::" + entry.getValue());
}