Using Arrays

Even if your array is filled with primitive ints, every array in Java is an object, and is treated as such. Arrays are objects. So there are a number of methods that you can put to work to get value out of them. It also means that you should comply with object assignment and equivalency tests, as well as state and local laws.

You can think of two-dimensional arrays as holding a row and column number, in that order. For example, take Table 14-1.

14-1. A Two Dimensional Array
 012
07846
1927892
2988166
3715689
4554345

This table represents a two-dimensional array that holds 5 rows and 3 columns. You would create such an array like this:

int[][] grades = new int[5][3];

The element at position [3][2] is 89. The element at position [0][0] ...

Get Java Garage 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.