Understanding Multi-dimension Arrays Hey guys can someone explain to me how a multi-dimension array can be pictured (like the rows or col) or something in the lines of pictures as given in the K & H book if possible I am not able to get a clear understanding of the M_D arrays For e.g. something like
byte b2  = new byte ;
How can I visualize this statement
Also it would be great if someone could point me to some good literature on Multi Dimensional arrays.
I think the key to visualizing the array dec you have is to remember that there are no multi-dimensional arrays in Java. What we are commonly calling multi-dimensional arrays are really arrays of arrays.
That said, you can think of a multi-dimensional array any way that mirrors how you are using it. For example, sometimes you can think of a two-dimensional array as a Cartesian coordinate system if you needed to track the coordinates of a fly on the ceiling. You can do the same thing for 3, 4, and n- dimensions.
I have used four or more dimensional arrays to keep totals in a report. For example, I was keeping running totals for health care costs for individual employees who are part of companies that are part of insurance groups that are summarized by regions that are totaled for the whole report. For example:
double  RunningTotals= new double [V][W][X][Y][Z]; Where V is the number of reports, which was 1. W is the number of regions covered in the query X is the number of insurance groups in the query Y is the number of companies in the query Z is the number of employees in the query
As I added a dollar amount for each employee, I added the amount to each summary bucket. As I printed each summary, I set each bucket to zero.
My point is that you don't have to picture multi-dimensional arrays the way Einstein would.
posted 14 years ago
Thanks Borderi, For taking the time with such a detailed post but unfortunetly I still not getting it
what I would like to understand is the legal integer values of x1, x2, x3, x4 so that the statment would not cause a runtime expcetion.This would also help me to understand the assignment of such an array to say a 2D or 2D array. K&H book has a great picture Pg 22 , Fig 1-3 for 2D array but I am not able to extend the idea to an 4 dimensional array.
Ethan, I had the same questions about a multi dimensional array. I will try to explain what i understood. Please correct me if i am wrong.
Single dimensional array
int x= new int; x is a reference variable to an array that can hold 3 integer values at x, x and x.
Multi dimensional array int x=new int ; x is a reference variable referring to an array that can hold references (not values like the single dimensional array) to another Single dimensional array at x,x,x. i.e say that x=1. then x is holding a reference to another Single dimension array which has a value 1 at index 0; x=2 then x is holding a referece to the above Single dimension array which has a value 2 at index 1;
So far so good.
I was confused when i saw a line similar to the following line in the K & B book.
int x =new int; After thinking about it for a while, I thougt that x is a reference variable holding refereces at x, x and x to other single dimensional arrays with the number of indices as 2 for each array.
i.e x would hold a reference to an array object that will have values at x and x
x would hold a refernce to an array object that will have values at x and x
similarly x would hold a reference to an array object that will have values at x and x.
The differece between the statements int x = new int and int x=new int is that the first statement does not specify the number of indices of the arrays which are reffered by either x, x or x where as the second statement specifies the number indices to each of the array referred by x, x and x as 2.
Excuse me if i am wrong or if i furter added to your confusion. All the Gurus out there please correct me if i am wrong.
posted 14 years ago
No one has posted their opinion on my explanation. I am still not sure if i was right! Could some guru please take time to view and post opinion? Thank you very much.
See ya later boys, I think I'm in love. Oh wait, she's just a tiny ad:
global solutions you can do at home or in your backyard