next up previous index
Next: Initialisation of Array Elements Up: Array Variables Previous: Initialisation of Array Variables   Index


Array Bounds

Arrays in Java are always zero-based. This means that the first element is a[0], the second is a[1] and so on. The previous assignment to a[2] refers to the third element of the array. Correspondingly the last element of the array is a[19]. Attempts to access a[20] or beyond will lead to an ArrayIndexOutOfBoundsException at runtime, as will negative values.



Peter Williams 2005-06-07