Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Matrix Length?

 
Josh Tambini
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what about arrayname.length ?
 
vannia hdz
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
meant arrayname.length();
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic