public class Test {
public static void main(String[] args) {
List> listMaps = new ArrayList>();
Map map1 = new HashMap();
map1.put("1", "a");
map1.put("2", "b");
map1.put("3", "c");
listMaps.add(map1);
Map map2 = new HashMap();
map2.put("11", "aa");
map2.put("22", "bb");
map2.put("33", "cc");
listMaps.add(map2);
for (Map map : listMaps) {
for (String s : map.keySet()) {
System.out.print(map.get(s) + " ");
}
}
System.out.println();
System.out.println("========================");
for (int i = 0; i < listMaps.size(); i++) {
Map map = listMaps.get(i);
Iterator iterator = map.keySet().iterator();
while (iterator.hasNext()) {
String string = (String) iterator.next();
System.out.println(map.get(string));
}
}
System.out.println("++++++++++++++++++++++++++++");
for (Map map : listMaps) {
for (Map.Entry m : map.entrySet()) {
System.out.print(m.getKey() + " ");
System.out.println(m.getValue());
}
}
System.out.println("-----------------------------");
}
}
打印的结果:
c b a bb cc aa
========================
c
b
a
bb
cc
aa
++++++++++++++++++++++++++++
3 c
2 b
1 a
22 bb
33 cc
11 aa
-----------------------------