FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   array length for 2nd dimension
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: array length for 2nd dimension  (Read 300 times)
sspboyd


array length for 2nd dimension
« on: May 5th, 2004, 12:09am »

Hi,
Is there a way to determine the length of the second dimension in an array?
 
I can get the length of the first dimension no problem, but I don't know if there is a way of getting the second.
 
Code:
int d1 =3;
int d2 =(int)random(3,6);
int[][] array = new int[d1][d2];
println("array.length = "+array.length);
 

gmail.com w/ sspboyd username
justo


Re: array length for 2nd dimension
« Reply #1 on: May 5th, 2004, 12:34am »

because a 2 dimensional array is really an array of arrays, in java at least, each sub-array can have its own length. its not very useful for pixel arrays or chess boards, but since arrays are just objects in java, it is strictly correct.
 
as a result, as far as i know, there is no "pretty" answer. the easiest way, if you know they are all of the same length, you can just ask the first one. ie
 
array[0].length
 
Pages: 1 

« Previous topic | Next topic »