File APIs for Java Developers Manipulate DOC, XLS, PPT, PDF and many others from your application. http://aspose.com/file-tools
Big Moose Saloon
 Search | Java FAQ | Recent Topics Register / Login

# multi-dimensional array

luk Hann
Ranch Hand

Joined: Jan 29, 2001
Posts: 48
Hi all,
How does three-dimensional array work?
Thanks.
Luk
Elisabeth Van
Ranch Hand

Joined: Feb 09, 2001
Posts: 42
Kind of a generic question, but I'll try to explain as best I can (and let me know how I do, because something I'm doing for work right now is preparing to teach an intro-level Java class--as little as I know, I happen to be the "expert" in our department )
Suppose the easiest way to start is with 2-dimensional arrays, which are easy to get a handle on--it's just an array of arrays.
So for instance, suppose I was keeping an array of the mileage at which I got the oil changed in my vehicles.
So suppose:
int miles[][] = new int[2][];
miles[0] = {3000, 6000, 9000, 12000, 15000};
miles[1] = {3000, 8000, 14000, 20000};
Pretty simple concept. Now, take it to 3 dimensions--we'll keep track of the mileage of everyone in the neighborhood
so now we would have miles[][][]
miles[0] = {{3000, 6000, 9000, 12000, 15000}, {3000, 8000, 14000, 20000}}; //me
miles[1] = {{3000, 6000, 10000}, {5000, 10000, 15000, 20000}, {3000, 7000}}; //my neighbor, who has 3 cars
and so on...
Hope that helps a little, or at least raises some further questions that'll help clarify thing.
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4285

2

good example

SCJP