• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

Find Width of two dimensional arrays in java

the length property of java arrays returns the number of rows, is there a way to determine the number of columns?

0
fbk2000
Asked:
fbk2000
  • 2
1 Solution
 
Mayank SAssociate Director - Product EngineeringCommented:
A one-D array will have only one dimension :) are you talking about multiple dimensions?
0
 
Mayank SAssociate Director - Product EngineeringCommented:
If its a 2-D array, then its like an array of arrays. Each inner array can have multiple lengths (multiple columns, if that's what you call it), so you will need to invoke length on each one of them individually.

String[][] a ;
// populate values into it

for ( int i = 0 ; i < a.length ; i ++ )
  System.out.println ( a[i].length ) ; // end for
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now