List
public static List<String> deepcopy(List<String> src) {
ByteArrayOutputStream byteout = new ByteArrayOutputStream();
List<String> dest = new ArrayList<String>();
try {
ObjectOutputStream out = new ObjectOutputStream(byteout);
out.writeObject(src);
ByteArrayInputStream bytein = new ByteArrayInputStream(byteout.toByteArray());
ObjectInputStream in = new ObjectInputStream(bytein);
dest = (List<String>) in.readObject();
} catch (Exception e) {
}
return dest;
}
map
map.putAll()
本文介绍了一种使用序列化方法实现List<String>深拷贝的技术方案,并提供了完整的Java代码示例。该方法适用于需要避免原始数据被意外修改的情况。
3129

被折叠的 条评论
为什么被折叠?



