Find Width of two dimensional arrays in java

Posted on 2004-11-13
Last Modified: 2010-03-31
the length property of java arrays returns the number of rows, is there a way to determine the number of columns?

Question by:fbk2000
    LVL 30

    Expert Comment

    A one-D array will have only one dimension :) are you talking about multiple dimensions?
    LVL 30

    Accepted Solution

    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

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
    For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
    Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
    Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now