The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
June 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Correct Design

Posted by Ivan Porty on June 09, 2000 at 12:44 AM

> > > How can I reference the size of a 2-dimensional/3-dimensional array using "array.length" ? Thanks!

> > I think that the array.length will correspond to the first number, on the Left Hand Side bracket. This is number of rows of element where each element is itself an array. Now, If we use the element.length, we can target the other bracket too.

> > I am not sure if that is the answer you are lookig for.

> I'm totally guessing here, but try array[n].length I think I read that the length of inner arrays can vary, so the above syntax seems like it could be correct...don't have a compiler here at work...and I'm new at Java, too

Hi, Sonny

Consider following array:
int[][][] array = new array[10][10][10];

Use following style:

1) To get first line length, use
array.length
2) To get second line length, specify its number
array[_line_number].length
3) To get third line, use the same technique:
array[_line_number][_line_number_2].length

That's all.





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us