private static <T extends Serializable> T clone(Map<String, Object> obj) {
T cloneObj = null;
try {
ByteOutputStream bos = new ByteOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(obj);
oos.close();
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bis);
cloneObj = (T) ois.readObject();
ois.close();
} catch (Exception e) {
e.printStackTrace();
}
return cloneObj;
}
public static void createListByLen(){
List<Integer> intArr = new ArrayList<Integer>(Collections.nCopies(4, 1));
System.out.println(intArr.toString());
Collections.fill(intArr, 2);
System.out.println(intArr.toString());
HashMap<String, Object> lzh = new HashMap<>();
lzh.put("name", "");
lzh.put("age", "");
lzh.put("sex", "");
lzh.put("phone", "");
lzh.put("bj", new ArrayList<>());
List<Map<String, Object>> dataList = new ArrayList<>(Collections.nCopies(3, new HashMap<>()));
Collections.fill(dataList, lzh);
Map<String, Object> map = clone(dataList.get(1));
map.put("name", "张三");
map.put("age", 18);
map.put("sex", "男");
map.put("phone", "110");
map.put("bj", new ArrayList<>());
dataList.set(1, map);
System.out.println(dataList);
}