<<< Declaring array as formal parameter to a method | Index | System.arraycopy, used prior to JDK 1.6 >>> |
Code that copies the values of an array with JDK 1.6 or later:
double[] grades = {92.3, 88.0, 95.2, 90.5}; double[] percentages = Arrays.copyOf( grades, grades.length); percentages[1] = 70.2; // doesn't change grades[1] System.out.println("grades[1]=" + grades[1]); // prints 88.0
Code that copies part of one array into another array
double[] grades = {92.3, 88.0, 95.2, 90.5}; Arrays.sort(grades); double[] lowestGrades = Arrays.copyOfRange(grades, 0, 2); double[] highestGrades = Arrays.copyOfRange( grades, 2, 4);
<<< Declaring array as formal parameter to a method | Index | System.arraycopy, used prior to JDK 1.6 >>> |