众所周知,java里要做到对可变对象的深拷贝是麻烦的,因为你总是引用的地址,下面这一段是一个利用序列化流实现的对象集合的深拷贝 public static List deepCopy(List src) throws IOException, ClassN
public staticList deepCopy(List src) throws IOException, ClassNotFoundException { ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(byteOut); out.writeObject(src); ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray()); ObjectInputStream in = new ObjectInputStream(byteIn); @SuppressWarnings("unchecked") List dest = (List ) in.readObject(); return dest; }