Use System.arraycopy ()
System.arraycopy(sourceArray, sourceStartIndex, targetArray, targetStartIndex, length);
Example
String[] source = { "alpha", "beta", "gamma" }; String[] target = new String[source.length]; System.arraycopy(source, 0, target, 0, source.length);
or use Arrays.copyOf ()
Example,
target = Arrays.copyOf(source, length);
java.util.Arrays.copyOf(byte[] source, int length) was added in JDK 1.6.
The copyOf() method uses System.arrayCopy() to create a copy of the array, but more flexible than clone() , since you can create copies of parts of the array.
Zaki Jul 25 '10 at 12:28 2010-07-25 12:28
source share