List数组对象深度copy,不影响原来的List

直接代码

	/**
	 * 
	 * @方法名称 deepCopy
	 * @功能描述 <pre>深度复制-不影响原来的list</pre>
	 * @作者    yw
	 * @创建时间 2020年8月17日 上午9:00:38
	 * @param src Listcopy源
	 * @return 返回一个全新的List
	 * @throws IOException
	 * @throws ClassNotFoundException
	 */
	public <T> List<T> deepCopy(List<T> 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<T> dest = (List<T>) in.readObject();  
	    return dest;  
	} 

 

Guess you like

Origin blog.csdn.net/xingsfdz/article/details/114691278
Recommended