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.
Thanks for the info.