Java Array Deep Copy deepCopy(Object objectArray)

Here you can find the source of deepCopy(Object objectArray)

Description

deep Copy

License

Apache License

Declaration

public static <T> T deepCopy(Object objectArray) 

Method Source Code

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

import java.util.Arrays;

public class Main {
    public static <T> T deepCopy(Object objectArray) {
        Class arrayClass = objectArray.getClass();

        if (boolean[].class.equals(arrayClass)) {
            boolean[] array = (boolean[]) objectArray;
            return (T) Arrays.copyOf(array, array.length);
        } else if (byte[].class.equals(arrayClass)) {
            byte[] array = (byte[]) objectArray;
            return (T) Arrays.copyOf(array, array.length);
        } else if (short[].class.equals(arrayClass)) {
            short[] array = (short[]) objectArray;
            return (T) Arrays.copyOf(array, array.length);
        } else if (int[].class.equals(arrayClass)) {
            int[] array = (int[]) objectArray;
            return (T) Arrays.copyOf(array, array.length);
        } else if (long[].class.equals(arrayClass)) {
            long[] array = (long[]) objectArray;
            return (T) Arrays.copyOf(array, array.length);
        } else if (float[].class.equals(arrayClass)) {
            float[] array = (float[]) objectArray;
            return (T) Arrays.copyOf(array, array.length);
        } else if (double[].class.equals(arrayClass)) {
            double[] array = (double[]) objectArray;
            return (T) Arrays.copyOf(array, array.length);
        } else if (char[].class.equals(arrayClass)) {
            char[] array = (char[]) objectArray;
            return (T) Arrays.copyOf(array, array.length);
        } else {/* w ww .ja va 2 s  .  co m*/
            Object[] array = (Object[]) objectArray;
            return (T) Arrays.copyOf(array, array.length);
        }
    }
}

Related

  1. deepCopy(byte[] org)
  2. deepCopy(double[][] in)
  3. deepCopy(final String s)
  4. deepCopy(int[] array)
  5. deepCopy(int[][] src, int[][] dest)
  6. deepCopy2DArray(float[][] a)
  7. deepCopyOf(double[][] src)