| Author |
size of 2D array
|
Alex Kravets
Ranch Hand
Joined: Jan 24, 2001
Posts: 476
|
|
Hi guys, How can I find out length of a 2d array that I get as a parameter of a function? If I have: public void getArray(String[][] arr){ } How can I find out what is the size of each dimension just by knowing from getArray() that this is a two-dimensional array? thanks, Alex
|
All right brain, you don't like me and I don't like you, but let's just do this one thing so I can get back to killing you with beer.<br /> <br />- Homer Simpson
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24057
|
|
Hi Alex, A Java 2D array is really a 1D array of 1D arrays -- i.e., there's a "backbone" array whose elements are 1D arrays, whose elements are (in your example) Strings. So if the array variable is named "arr", then "arr.length" is one dimension, the length of the backbone. The other dimension can technically be different for every element of the backbone -- the array doesn't have to be "rectangular," it can be "ragged." But if you know that it is rectangular, then the other dimension is just "arr[0].length".
|
[Jess in Action][AskingGoodQuestions]
|
 |
Alex Kravets
Ranch Hand
Joined: Jan 24, 2001
Posts: 476
|
|
thanks
|
 |
 |
|
|
subject: size of 2D array
|
|
|