Tuesday, April 29, 2008

How to copy an array into another

If the array only contains primitive types or if you want to copy only the object references, not duplicate the objects, then you can use the following method

java.lang.System.arraycopy(Object src, int src_position,
Object dst, int dst_position, int length);

Otherwise, if you want to duplicate the objects, you have to initialize your new array and write a loop that duplicates each object in the old array into the new one.

For more details: Java Tips



No comments: