Unit 4 · Data Collections
Array Basics
Practice mode with 15 Java-focused questions, immediate answer checks, and explanations.
What array basics covers
An array holds a fixed number of elements of one type, created either with new int[n] or with an initializer list. Arrays created with new start at default values: 0 for int, 0.0 for double, false for boolean, and null for object types. The size is available through the length field, written without parentheses, and valid indexes run from 0 through length - 1.
Where students lose points
Writing length() for an array or length for a String is a persistent mix-up. Students also assume an array of objects starts with usable objects rather than nulls, which leads to a NullPointerException, and they try to resize an array after creation, which Java does not allow.
How it shows up on the AP exam
Unit 4 data collections. Array fundamentals are assumed knowledge in every array FRQ, so default values and the length field are worth having fully automatic.
For practice use only.
Array Basics MCQ Practice
AP CSA array basics practice: declaration and initialization, default element values, the length field, and valid index ranges on the exam.
Answered 0 of 15
Choose one answer.
Which option matches the complete output produced by this segment?
public class ArrayBasicsContext
{
public static void runExample()
{
int[] a = new int[4];
a[2] = 7;
System.out.print(a.length + " " + a[0] + " " + a[2]);
}
public static void main(String[] args)
{
runExample();
}
}