I\'m trying to iterate List in Java. However, I\'m not able to iterate it properly. Can any one guide me?
Itera
You iterate over a list with elements of type Map. So casting to Map.Entry will give you a ClassCastException.
Try it like this
Iterator it = list.iterator();
while (it.hasNext()) {
Map map = (Map) it.next();
for (Map.Entry entry : map.entrySet()) {
System.out.println(entry.getKey() + " = " + entry.getValue());
}
}
It would be easier for you, if you didn't use the raw types Iterator and Map.Entry. Use generics wherever possible. So the code would look like this:
Iterator