I\'m trying to iterate List> in Java. However, I\'m not able to iterate it properly. Can any one guide me?
List>
Itera
public static void main(String[] args) { List> myListOfMaps = new ArrayList>(); Map map1 = new HashMap(); map1.put("Fname", "Ankur"); Map map2 = new HashMap(); map2.put("Lname", "Singhal"); myListOfMaps.add(map1); myListOfMaps.add(map2); for (int i = 0 ; i < myListOfMaps.size() ; i++) { Map myMap = myListOfMaps.get(i); System.out.println("Data For Map" + i); for (Entry entrySet : myMap.entrySet()) { System.out.println("Key = " + entrySet.getKey() + " , Value = " + entrySet.getValue()); } } }
output
Data For Map0 Key = Fname , Value = Ankur Data For Map1 Key = Lname , Value = Singhal