package com.xrluo.type09;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class Demo3
{public static void main(String[] args)
{ArrayList<Map<String, Object>> list = new ArrayList<>();
HashMap<String, Object> map = new HashMap<>();
/*
这个中央是不是能够了解为 list map 都是指向一个内存的地址
*/
map.put("key1","value1");
map.put("key2","value2");
/*
{key1=value1, key2=value2}
此处是不是能够了解为 把 map 的内存地址存入到 list 中
*/
list.add(map);
/*
[{key1=value1, key2=value2}]
*/
/*
此处持续操作的事 map 的内存地址中的数据, 所以会替换了下面的数据
*/
map.put("key1","value3");
map.put("key2","value4");
/*
list == [{key1=value3, key2=value4}]
*/
list.add(map);
/*
list == [{key1=value3, key2=value4}, {key1=value3, key2=value4}]
*/
System.out.println(list);
System.out.println(map);
}
}
package com.xrluo.type09;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class Demo3
{public static void main(String[] args)
{ArrayList<Map<String, Object>> list = new ArrayList<>();
HashMap<String, Object> map;
map = new HashMap<>();
map.put("key1","value1");
map.put("key2","value2");
list.add(map);
/*
[{key1=value1, key2=value2}]
*/
map = new HashMap<>();
map.put("key1","value3");
map.put("key2","value4");
/*
list == [{key1=value1, key2=value2}]
*/
list.add(map);
/*
list == [{key1=value1, key2=value2}, {key1=value3, key2=value4}]
*/
System.out.println(list);
System.out.println(map);
}
}