Forums Register Login

size of 2D array

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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".
+Pie Number of slices to send: Send
thanks
The knights of nee want a shrubbery. And a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1129 times.
Similar Threads
Finding number of a rows in a resultset...
How expression is working
Access an array, from different class. How?
Array in Method Two Questions? Any one know how to do them?
2D array
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 04:32:54.