How do I copy the contents of an array (with primitive type contents) to another array?
. Use the method java.lang.System.arraycopy(Object src, int src_position, Object dst, int dst_position, int length); Note that there is no corresponding method to clear an array to 0.0, 0, null, false, ‘\u0000’ etc. This has lead several people to suggest the old COBOL trick of “initialize by rollup”. In initialize by roll-up, the programmer sets the first element of the array to the desired value, and then moves elements array[0 to n-1] to array[1 to n]. Under some old IBM COBOL compilers, code was generated to move element 0 to 1, then 1 to 2, and so on, “rolling up” the desired value through the array. It was always a terrible idea, as it went outside the boundaries of defined behavior in COBOL, and was subject to being broken in any compiler release. In any event, intialization by roll-up is defined not to work in Java. If the src and dst arguments refer to the same array object, then the copying is performed as if the components at positions srcOffset through srcOffset+length-1 we