Size of 2 dimensional array

C

Chuck M.

Hi. I have a simple question, how do I find the length of a two
dimensional array? I want to know how to find how many rows are in an
array and how many columns are in each row. Thanks.
 
D

Daniel Pitts

Chuck said:
Hi. I have a simple question, how do I find the length of a two
dimensional array? I want to know how to find how many rows are in an
array and how many columns are in each row. Thanks.
Object[] foo = new Object[10];

foo.length will be 10...

Object[][] foo = new Object[10][];
foo[0] = new Object[25];
foo[1] = new Object[15];

foo.length = 10;
foo[0].length = 25;
foo[1].length = 15;


You can't know the length of every row unless you test them all. Thats
the down side to a two dimensional array in Java. You'll probably be
better off using some other mechanism for your storage. Arrays are way
too primitive anyway.
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top