fork download
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class Main {
  5. public static void main(String[] args) {
  6. int[][] a = {{ 1, 2 }, {3, 4, 5}};
  7. int[][] b = deepCopy(a);
  8. System.out.println(Arrays.deepToString(b));
  9. }
  10.  
  11. private static <T> T deepCopy(T obj) {
  12. try {
  13. oos.writeObject(obj);
  14. oos.close();
  15. ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
  16. @SuppressWarnings("unchecked")
  17. T result = (T) ois.readObject();
  18. return result;
  19. } catch (Exception e) {
  20. }
  21. }
  22. }
Success #stdin #stdout 0.09s 380480KB
stdin
Standard input is empty
stdout
[[1, 2], [3, 4, 5]]