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

Distributed Transactions

What is a distributed transaction?  Transactions that span over multiple physical systems or computers over the network, are simply termed D...