How do I iterate over an Arraylist of Hashmaps
807601Mar 3 2008 — edited Mar 3 2008Hello, I'm new to java, but have been programming for quite some time. My question is "How do I iterate over an Arraylist of Hashmaps?". I have the following code fragment
List displayParamList = new ArrayList();
pubic void setList() {
// I have a global String array that contains my label and label values
for (int i=0; i<2; i++) {
Map row = new LinkedHashMap();
row.put(this.label,this.labelValue[i]);
this.displayParamList.add(row);
}
}
// Now that function works fine because I can print the "this.displayParamList" object and
// see the key value pairs in the order that I placed them onto the arraylist
// The following function is the problem
public String setDisplayString() {
String displayString = "";
for (int i=0; i<this.displayParamList.size(); i++ ) {
Map.Entry entry = (Map.Entry) this.displayParamList.get(i);
String key = (String) entry.getKey();
String value = (String) entry.getValue();
displayString = displayString + key ": " + value;
}
return displayString;
}
// The program basically stops when it hits the Map.Entry line, What I'm doing wrong here?