You access an array element by referring to the index number.

This statement accesses the value of the first element in cars:

Example

String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
System.out.println(cars[0]);
// Outputs Volvo
 

Note: Array indexes start with 0: [0] is the first element. [1] is the second element, etc.



Practice Excercise Practice now