package Test;
import java.util.*;
public class Test {
public static void main(String[] args) {
//第一种:直接加入
List<Map<String, Object>> list1 = new ArrayList<Map<String, Object>>();
Map<String, Object> m1 = new HashMap<String, Object>();
m1.put("age", "55");
m1.put("name", "66");
list1.add(m1);
System.out.println(list1);
//[{name=66, age=55}]
//第二种:直接插入,但是key永远只对应一个value
List<Map<String, Object>> list2 = new ArrayList<Map<String, Object>>();
Map<String, Object> m = new HashMap<String, Object>();
m.put("age", "55");
m.put("name", "66");
list2.add(m);
for (Map<String, Object> m2 : list2) {
m2.put("key", "123");
}
System.out.println(list2);
//[{name=66, age=55, key=123}]
//第三种:能插入多个值,就是一个key能对应多个value
List<Map<String, Object>> list3 = new ArrayList<Map<String, Object>>();
Map<String, Object> m3 = new HashMap<String, Object>();
m3.put("age", "55");
m3.put("name", "66");
for (int i = 0; i < 2; i++) {
Map<String, Object> mm = new HashMap<String, Object>();
mm.putAll(m3);
mm.put("key1", i);
list3.add(mm);
}
System.out.println(list3);
//[{name=66, key1=0, age=55}, {name=66, key1=1, age=55}]
}
}