Java Object Deep Copy deepCopy(List src)

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

Description

deep Copy

License

Apache License

Declaration

public static <T> List<T> deepCopy(List<T> src) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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) {
        ByteArrayOutputStream byteOut = null;
        ObjectOutputStream out = null;
        try {//  w w w.  jav a 2 s.co  m
            byteOut = new ByteArrayOutputStream();
            out = new ObjectOutputStream(byteOut);
            out.writeObject(src);

            ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
            ObjectInputStream in = new ObjectInputStream(byteIn);
            @SuppressWarnings("unchecked")
            List<T> dest = (List<T>) in.readObject();
            return dest;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        } finally {
            if (byteOut != null) {
                try {
                    byteOut.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (out != null) {
                try {
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}

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)
  8. deepCopy(Object orig)