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.
Daniel Pitts - 08 Nov 2007 01:51 GMT
> 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.

Signature
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
Roedy Green - 08 Nov 2007 03:38 GMT
>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.
see http://mindprod.com/jgloss/array.html#MATRIXGOTCHAS

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Christian - 08 Nov 2007 10:53 GMT
Roedy Green schrieb:
>> 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.
>
> see http://mindprod.com/jgloss/array.html#MATRIXGOTCHAS
I specially liked that sentence in the article:
"Arrays are like virgins. They are very careful about what they allow in
themselves."
Chuck M. - 08 Nov 2007 04:11 GMT