Java Object Deep Copy deepCopy(List src)

Here you can find the source of deepCopy(List src)

Description

deep Copy

License

Open Source License

Declaration

public static <T> List<T> deepCopy(List<T> src) throws IOException, ClassNotFoundException 

Method Source Code


//package com.java2s;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import java.util.List;

public class Main {
    public static <T> List<T> deepCopy(List<T> src) throws IOException, ClassNotFoundException {

        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(byteOut);
        out.writeObject(src);//from  w w  w.jav  a2s  . c om

        ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
        ObjectInputStream in = new ObjectInputStream(byteIn);
        @SuppressWarnings("unchecked")
        List<T> dest = (List<T>) in.readObject();
        return dest;
    }
}

Related

  1. deepCopy(File fromDir, File toDir)
  2. deepCopy(final Class c, final Serializable s)
  3. deepCopy(final Object oldObj)
  4. deepCopy(List src)
  5. deepCopy(Object o)
  6. deepCopy(Object obj1, Object obj2)
  7. deepCopy(Object oldObj)