AP CSA

Arrays To facts …

Topic Basic Intermediate Advanced
Array creation
Declare and initialize one dimensional array variables with array initializers, e.g. int[] nums = {1, 2, 3};
Declare and initialize one-dimensional array variables with new, e.g. int[] nums = new int[10];
Declare and initialize rectangular 2d arrays with both array initializers and new.
Declare and initialize non-rectangular 2d arrays.
Array element access
Access the first element of an array: a[0].
Access the last element of an array: a[a.length - 1]
Access arbitrary elements of an array: a[i]
Access arbitrary elements of a 2d array: a[row][col].
Access array elements using computed values for the index.
Access arbitrary elements relative to the end of an array using a.length, e.g. a[a.length - 3].
Use array access expressions as sub expressions in larger expressions, e.g.: a[i] < a[i + 1]
Explain what an ArrayIndexOutOfBoundsException means.
Array element assignments
Assign a value to the first element of an array: a[0] = value
Assign a value to the last element of an array: a[a.length - 1] = value
Assign values to arbitrary array elements: a[i] = value
Assign values to arbitrary elements of a 2d array: a[row][col] = value
Modify array elements using computed values for the index.
Modify arbitrary elements relative to the end of an array using a.length, e.g. a[a.length - 3].
Modify array elements with compound assignment operators, e.g. a[i] += 10
Write code to swap to elements in an array.
Arrays as values
Explain why arrays have to be a reference type.
Explain why modificatios to an array referred to by one variable can be visible if you reference the same array via another variable.
Explain what a = b does if a and b are both variables holding an array value.
Explain roughly how arrays are stored in memory and the relationship between a reference to an array and the actual memory holding the array.
Explain what is stored in an array of reference type, e.g. String[].
Explain how 2D arrays are stored in memory.