Array Initialization

An array in Java is a type of object that can contain a number of variables. These variables can be referenced only by the array index—a nonnegative integer. The first element in an array has an index of 0.

All of these contained variables, or elements, must be the same type, which is the type of the array. Every array has an associated length variable, established when the array is created, which you can access directly. If you try to address an element with an index that is outside the range of the array, an exception is generated. Java arrays are one dimensional, but an array can contain other arrays, which gives the effect of multiple dimensions.

You can have arrays of any of the Java primitives or reference variables. ...

Get Java 2™ Programmer Exam Cram™ 2 (Exam CX-310-035) now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.