Page 339 - AP Computer Science A, 7th edition
P. 339
Original array: 1 2 3 4 Modified array: 1 2 3 4
A look at the memory slots shows why the list remains unchanged.
The point of this is that primitive types—including single array elements of type int or double—are passed by value. A copy is made of the actual parameter, and the copy is erased on exiting the method.
Example 4
/∗ ∗ Swap arr[i] and arr[j] in array arr. ∗ / public static void swap(int[] arr, int i, int j) {
int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp;
}