Java: Copy array of non-primitive type
What is the prefered way to copy an array of a non-primitve type in Java? How about performance issues? The old school way was: public static void java.lang.System.arraycopy(Object src, int srcPos, Object dest, int destPos, int length) This copys from one existing array to another. You have to allocate the new array yourself ... assuming that you are making a copy of an array. From JDK 6 onwards, the java.util.Arrays class has a number of copyOf methods for making copies of arrays, with a new size. The ones that are relevant are: public static <T> T[] copyOf(T[] original, int newLength) and