Java tutorial
//package com.java2s; import java.io.*; public class Main { public static Object cloneObject(Object obj) { try { ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(byteOut); out.writeObject(obj); ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray()); ObjectInputStream in = new ObjectInputStream(byteIn); return in.readObject(); } catch (IOException | ClassNotFoundException e) { e.printStackTrace(); } return null; } }