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 66k
  • Answers 66k
  • 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
  • added an answer Check out my answer to this question: surfing with the… May 11, 2026 at 11:40 am
  • added an answer The File.Exists method exists primarily for testing for the existence… May 11, 2026 at 11:40 am
  • added an answer This isn't really specific to Win32 exceptions; the question is,… May 11, 2026 at 11:40 am

Related Questions

I have a simple 2D array of strings and I would like to stuff
I have a 2D bitmap-like array of let's say 500*500 values. I'm trying to
I have c++ code that attempts to dynamically allocate a 2d array of bytes
I have a large 2d array that I serialize and base64_encode and throw into
So I have a large 2d array that i serialize, but when I attempt
I have a 2D image randomly and sparsely scattered with pixels. given a point
I have a 2D area with dots distributed on this area. I now am
I have a string like this that I need to parse into a 2D
I am working on a 2D scrolling game for iPhone. I have a large
I have a large number of 2D points and I want to quickly get

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.