Java tutorial
//package com.java2s; import java.lang.reflect.Array; public class Main { /** * Produces a copy of the given array; * @param array the array to copy. * @param <T> Any type * @return the copy of the given array; */ public static <T> T[] duplicateArray(T[] array) { @SuppressWarnings("unchecked") T[] copy = (T[]) Array.newInstance(array.getClass().getComponentType(), array.length); System.arraycopy(array, 0, copy, 0, array.length); return copy; } public static byte[] duplicateArray(byte[] array) { byte[] copy = new byte[array.length]; System.arraycopy(array, 0, copy, 0, array.length); return copy; } public static short[] duplicateArray(short[] array) { short[] copy = new short[array.length]; System.arraycopy(array, 0, copy, 0, array.length); return copy; } public static int[] duplicateArray(int[] array) { int[] copy = new int[array.length]; System.arraycopy(array, 0, copy, 0, array.length); return copy; } public static long[] duplicateArray(long[] array) { long[] copy = new long[array.length]; System.arraycopy(array, 0, copy, 0, array.length); return copy; } public static char[] duplicateArray(char[] array) { char[] copy = new char[array.length]; System.arraycopy(array, 0, copy, 0, array.length); return copy; } public static boolean[] duplicateArray(boolean[] array) { boolean[] copy = new boolean[array.length]; System.arraycopy(array, 0, copy, 0, array.length); return copy; } public static double[] duplicateArray(double[] array) { double[] copy = new double[array.length]; System.arraycopy(array, 0, copy, 0, array.length); return copy; } public static float[] duplicateArray(float[] array) { float[] copy = new float[array.length]; System.arraycopy(array, 0, copy, 0, array.length); return copy; } }