
In a for loop,using the con-
dition:
i <= arrayName.length
will generate an ArrayIn-
dexOutOfBoundsException
because the index of the
last element of an array is
arrayName.length – 1.
COMMON ERROR
TRAP
474 CHAPTER 8 Single-Dimensional Arrays
For example, attempting to print the array using the array name will not
print all the elements of the array. Instead, this statement:
System.out.println( cellBills ); // incorrect attempt to print array!
calls the toString method of the Array class, which simply prints the name
of the object’s class and the hash code of the array name, for example,
[D@310d42.
8.3.1 Printing Array Elements
To print all elements of an ar ...