<<< Copy an array with Arrays.copyOf, JDK 1.6+ | Index | How to copy an array prior to JDK 1.6 (cont.) >>> |
The syntax of the arraycopy method of the System class
System.arraycopy( fromArray, intFromIndex, toArray, intToIndex, intLength);
Code that copies the values of an array
double[] grades = {92.3, 88.0, 95.2, 90.5}; double[] percentages = new double[grades.length]; System.arraycopy( grades, 0, percentages, 0, grades.length); percentages[1] = 70.2; // doesn't change grades[1] System.out.println("grades[1]=" + grades[1]); // prints 88.0
<<< Copy an array with Arrays.copyOf, JDK 1.6+ | Index | How to copy an array prior to JDK 1.6 (cont.) >>> |