public static <T> List<T> depCopy(List<T> srcList) {
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
try {
ObjectOutputStream out = new ObjectOutputStream(byteOut);
out.writeObject(srcList);
ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
ObjectInputStream inStream = new ObjectInputStream(byteIn);
List<T> destList = (List<T>) inStream.readObject();
return destList;
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return null;
}
//调用方法
List<Map> list1=new ArrayList();
List<Map> newList = new ArrayList<Map>(AllPathdata.subList(0, 20));
list1 = depCopy(newList);
注意一点list的subList方法没有实现序列化,需要重新赋值得到一个list中在对list执行方法。