Unit 4 · Data Collections
Array Mutation
Practice mode with 15 Java-focused questions, immediate answer checks, and explanations.
What array mutation covers
Changing an array means assigning into an indexed position, as in arr[i] = value. The enhanced for loop cannot do this, because its variable is a copy of the element rather than the storage location itself. Arrays are reference types, so passing one to a method or assigning it to another variable shares the same underlying storage: changes made through either name are visible through both.
Where students lose points
The enhanced-for assignment trap catches almost everyone once. Aliasing is the deeper misunderstanding: students expect int[] b = a; to copy, then are surprised when writing through b changes a. Shifting elements also goes wrong when the loop direction overwrites values that are still needed.
How it shows up on the AP exam
Unit 4 content with a strong pass-by-reference thread running through it. Methods that modify arrays in place are a standard FRQ task and a favorite MCQ subject.
For practice use only.
Array Mutation MCQ Practice
AP CSA array mutation practice: assigning into elements, why enhanced for loops cannot modify arrays, shifting values, and array reference aliasing.
Answered 0 of 15
Choose one answer.
Which option matches the complete output produced by this segment?
public class ArrayMutationContext
{
public static void runExample()
{
int[] a = {1, 2, 3};
a[1] = a[0] + a[2];
System.out.print(a[0] + " " + a[1] + " " + a[2]);
}
public static void main(String[] args)
{
runExample();
}
}