• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Two-dimensional array lengths????

 
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do I find out the length of a row in a 2-dimensional array. For exanmple if i have [x][y], how do i find the legnth of x? the .length method seems to give me the length of y.

Cheers
[ February 06, 2006: Message edited by: Sam Bluesman ]
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A two-dimensional array in Java is just an array of arrays. Try this:
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Keep in mind that a 2-d array does not need to be "rectangular," and could contain arrays of different lengths.

For example, if "myArray" represents a 2-d array, then the array at myArray[0] is not necessarily the same length as the array at myArray[1]...

int[][] myArray = { {1}, {2, 3, 4}, {5, 6} };
 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by marc weber:
Keep in mind that a 2-d array does not need to be "rectangular," and could contain arrays of different lengths.

For example, if "myArray" represents a 2-d array, then the array at myArray[0] is not necessarily the same length as the array at myArray[1]...

int[][] myArray = { {1}, {2, 3, 4}, {5, 6} };



Which also means that :
int[][] myArray = new int[3][];
myArray[0] = new int[1];
myArray[1] = new int[3];
myArray[2] = new int[2];
And you should not forget initialze the arrays
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by memati bas:
...And you should not forget initialze the arrays



Do you mean like this:

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic