Monday, December 30, 2013

Iterate Over a Map in Java

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.

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());

}

No comments:

Post a Comment

Understanding Essential DNS Record Types for Web Administrators

  Understanding Essential DNS Record Types for Web Administrators Introduction The Domain Name System (DNS) acts as the backbone of the inte...