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

Matrix Length?

Josh Tambini

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

both doesnt seem to work...
vannia hdz

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

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

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
I agree. Here's the link: http://aspose.com/file-tools
subject: Matrix Length?
It's not a secret anymore!