Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2007

Tip: Looking for answers? Try searching our database.

Size of 2 dimensional array

Thread view: 
Chuck M. - 08 Nov 2007 01:43 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.
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
Thank you everyone.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.