wood burning stoves*
The moose likes Beginning Java and the fly likes Matrix Length? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Matrix Length?" Watch "Matrix Length?" New topic
Author

Matrix Length?

Josh Tambini
Greenhorn

Joined: Nov 30, 2004
Posts: 24
how do i find the length of a matrix (2d array)???
tried this:
arrayname[][].length;
and also this:
arrayname[].length;

both doesnt seem to work...
vannia hdz
Greenhorn

Joined: Jun 04, 2004
Posts: 14
what about arrayname.length ?
vannia hdz
Greenhorn

Joined: Jun 04, 2004
Posts: 14
meant arrayname.length();
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Remember, a multi-dimensional array is simply an array of arrays, each of which might be a different length.

So if arrayName is a 2-dimensional array, then arrayName.length gives the first dimension; and iterating through each arrayName[x].length (up to arrayName.length) gives the "second" dimensions -- which are the lengths of each first-dimension instance.

vannia: Note that in an array (unlike String), length is a variable -- not a method. So this would be a.length -- not a.length().
[ December 01, 2004: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Matrix Length?