Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4594224
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:47:52+00:00 2026-05-21T22:47:52+00:00

How to find the lengths of a multidimensional array with non equal indices? For

  • 0

How to find the lengths of a multidimensional array with non equal indices?

For example, I have int[][] pathList = new int[6][4]

Without actually hard-coding the indices, I need to find the ‘6’ and the ‘4’.

I can find the 6 with pathList.length, but how to obtain the ‘4’?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T22:47:52+00:00Added an answer on May 21, 2026 at 10:47 pm

    This will give you the length of the array at index i

    pathList[i].length
    

    It’s important to note that unlike C or C++, the length of the elements of a two-dimensional array in Java need not be equal. For example, when pathList is instantiated equal to new int[6][], it can hold 6 int [] instances, each of which can be a different length.


    So when you create arrays the way you’ve shown in your question, you may as well do

     pathList[0].length
    

    since you know that they all have the same length. In the other cases, you need to define, specific to your application exactly what the length of the second dimension means – it might be the maximum of the lengths all the elements, or perhaps the minimum. In most cases, you’ll need to iterate over all elements and read their lengths to make a decision:

    for(int i = 0; i < pathList.length; i++)
    {
        int currLen = pathList[i].length;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a multidimensional array that looks like this: Array ( [0] => Array
I want to find out if length property for Java arrays is an int/long
Problem: I have two arrays that can possibly be different lengths. I need to
I have two very large strings and I am trying to find out their
How do you find out the length/size of the data in an ntext column
In XLST how would you find out the length of a node-set?
I find that getting Unicode support in my cross-platform apps a real pain in
I find the concept of the programmable, tiling, keyboard-focuessed window manager ion3 very appealing,
I find from reading perldoc perlvar, about a thousand lines in is help for
I find that the .NET event model is such that I'll often be raising

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.