Page 359 - AP Computer Science A, 7th edition
P. 359

1. In Example 6 a for-each loop is used because each element is accessed without changing the list. An iterator operates unseen in the background. Contrast this with Example 6 above, where the list is changed by removing elements. Here you cannot use a for-each loop.
2. To test for a negative value, you could use
if (itr.next() < 0)
because of auto-unboxing.
3. Use a for-each loop for accessing and modifying objects in a
list. Use an iterator for removal of objects.
TWO -D IMEN S IO N AL ARRAYS
A two-dimensional array (matrix) is often the data structure of choice for objects like board games, tables of values, theater seats, and mazes.
Look at the following 3 × 4 matrix:
2687 1540 9328
If mat is the matrix variable, the row subscripts go from 0 to 2 and the column subscripts go from 0 to 3. The element mat[1][2] is 4, whereas mat[0][2] and mat[2][3] are both 8. As with one- dimensional arrays, if the subscripts are out of range, an ArrayIndexOutOfBoundsException is thrown.
Declarations
Each of the following declares a two-dimensional array:
  





















































































   357   358   359   360   361