Guided Notes

Arrays

Creating arrays, indexes and length, looping through arrays, the Arrays class, and 2-D arrays.

Creating arrays

Slide 1 / 5

An array stores a fixed number of values of one type:

String[] cars = {"Volvo", "BMW", "Ford"}; int[] scores = new int[5]; // five zeros

Access elements by index, starting at 0: cars[0] β†’ "Volvo" cars[1] = "Opel"; // change an element cars.length β†’ 3

An array's size is fixed when it's created. Using an index outside 0 to length βˆ’ 1 throws ArrayIndexOutOfBoundsException.

← Control Flow