AP® Computer Science A glossary
ArrayIndexOutOfBoundsException
Course: AP® Computer Science A Shows up in: Unit 4: Data Collections
The run-time exception thrown when code uses an array index less than 0 or greater than or equal to the array's length.
Appears in the course and exam description (CED): 4.3.A.6
The code compiles; the exception stops the program when the bad index is used. A loop condition such as i <= arr.length is the most common cause.
int[] laps = {60, 58};
System.out.println(laps[2]);
Output:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2 Learn it properly, with a checkpoint 4.3 Array Creation and Access