7.5 Multidimensional Arrays
Never trust to general impressions, my boy, but concentrate yourself upon details.
—SIR ARTHUR CONAN DOYLE, A Case of Identity (Sherlock Holmes)
An array having more than one index is sometimes useful. For example, suppose you wanted to store the dollar amounts shown in Figure 7.6 in some sort of array. The highlighted part of the table contains 60 such entries. If you use an array that has one index, the length of the array would be 60. Keeping track of which entry goes with which index number would be difficult. On the other hand, if you allow yourself two indices, you can use one index for the row of this table and one index for the column. Such an array is illustrated in Figure 7.7.
Get Java: An Introduction to Problem Solving and Programming, 8th Edition 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.