Size of multi-dimensional array

T

tim

How do you determine the size of a multi-dimensional array? I have a
2Xn array and I want to determine what n is so I can load the array
into a hash table.
 
M

Mike Schilling

How do you determine the size of a multi-dimensional array? I have a
2Xn array and I want to determine what n is so I can load the array
into a hash table.

If you know it's a square array (i.e. that all the elements of the outer
array are the same length), try

arr.length * arr[0].length;

If not, a precise answer would require

int sum = 0;
for (int i = 0; i < arr.length; i++)
sum += arr.length;
 
K

Knute Johnson

How do you determine the size of a multi-dimensional array? I have a
2Xn array and I want to determine what n is so I can load the array
into a hash table.

array[0].length;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top