Iterate HashMap in Java:

HashMap is widely used across java and J2EE application to handle key value pairs. With the introduction of Generics in JAVA 1.5, HashMap becomes more important and can contains a set of predefined key and values. An example in given below:

HashMap<Integer, ArrayList<String>> custDataKey = new HashMap<Integer, ArrayList<String>> custDataKey();

In the above example, we have a HashMap with Integer as a key and an ArrayList of strings as a value. Note that, the Value is again a collection of type String.

In order to Iterate the above Map, we use the below line of code:

HashMap<Integer, ArrayList<String>> custDataKey = new HashMap<Integer, ArrayList<String>> custDataKey();


Iterator< Map.Entry< Integer,ArrayList<String>>> securityEnt=guaranteeMap.entrySet().iterator();

while(securityEnt.hasNext()){

Map.Entry< Integer,ArrayList<String>> aSecuritySummaryMap=securityEnt.next();


int rowIndex=aSecuritySummaryMap.getKey();

ArrayList<String> secRowVal=aSecuritySummaryMap.getValue();

}

This way, we can easily iterate over a hashmap in java.




Sandeep Joshi
Mathematics, Technology and Programming are my passion. I am a part of Java Ecosystem and through this blog, I contribute to it. I am here to blog about my interests, views and experiences.
I am on Google+ and Facebook.
I feel proud to be listed as a "National Memory Record Holder" in the Limca Book of Records, 2009 and have attempted for an International Memory record in the Guiness Book of Records. I can remember the value of PI upto 10,000 digits after the decimal (3.1415.....). You can contact me on javagenious.com(At)gmal.com ; I would like to hear from you :)