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

  • SEARCH
  • Home
  • 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 152201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:34:51+00:00 2026-05-11T09:34:51+00:00

I have a 2D array of doubles in Java which is basically a table

  • 0

I have a 2D array of doubles in Java which is basically a table of values and I want to find out how many rows it has…

It is declared elsewhere (and allocated) like this:

double[][] table; 

then passed to a function…

private void doSomething(double[][] table) {  } 

In my function I want to know the length of each dimension without having to pass them around as arguments. I can do this for the number of columns but don’t know how to do it for the rows…

int cols = table[0].length; int rows = ?; 

How do I do that?

Can I just say…

int rows = table.length; 

Why would that not give rows x cols?

  • 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. 2026-05-11T09:34:52+00:00Added an answer on May 11, 2026 at 9:34 am

    In Java a 2D array is nothing more than an array of arrays.

    This means that you can easily get the number of rows like this:

    int rows = array.length; 

    This also means that each row in such an array can have a different amount of elements (i.e. each row can have a varying number of columns).

    int columnsInFirstRow = array[0].length; 

    This will only give you the number of columns in the first row, but the second row could have more or less columns than that.

    You could specify that your method only takes rectangular arrays and assume that each row has the same number of columns than the first one. But in that case I’d wrap the 2D-array in some Matrix class (that you might have to write).

    This kind of array is called a Jagged Array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 79k
  • Answers 79k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I suppose you are not generating the XML with suitable… May 11, 2026 at 4:12 pm
  • Editorial Team
    Editorial Team added an answer Masks in Flash can be unpredictable. Try setting cacheAsBitmap to… May 11, 2026 at 4:12 pm
  • Editorial Team
    Editorial Team added an answer I was investigating a solution to this almost a year… May 11, 2026 at 4:12 pm

Related Questions

I need a way to represent a 2-D array (a dense matrix) of doubles
Edit: I apologize everybody. I used the term jagged array when I actually meant
Hy all, I believe that the following piece of code is generating memory leak?
Is there an easy way to reference a column in a 2-D array as

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.