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 9223983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:12:17+00:00 2026-06-18T04:12:17+00:00

I found this topic on a similar Stack Overflow thread . In c++, when

  • 0

I found this topic on a similar Stack Overflow thread.

In c++, when you make an array int[i][j] you get row major order, so iterating by row will give you caches which contain more useful data.

In java, there is no 2d array, but it still creates something similar enough in terms of caches. My question is, does it create the arrays of actual data in the size of row, or does it create the array of pointers in size of row?

Or, as the top answer on the similar Stack Over thread said, does it do something entirely different where int[5][8] would be an array of 5 pointers to arrays of any size that all add up to (5*8)?

It said java makes jagged arrays, and I can’t think of any good reason for this to be true.

  • 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-06-18T04:12:18+00:00Added an answer on June 18, 2026 at 4:12 am

    In java, there is no 2d array, but it still creates something similar enough in terms of caches

    I don’t know about the C++ behaviour, but it sounds like you’re expecting something in the Java behaviour which may very well not be the case. If you write:

    int[][] x = new int[5][8];
    

    then that’s equivalent to:

    int[][] x = new int[5][];
    x[0] = new int[8];
    x[1] = new int[8];
    x[2] = new int[8];
    x[3] = new int[8];
    x[4] = new int[8];
    

    There are 6 separate arrays here. At any point, you could write:

    x[2] = new int[10000];
    

    It’s just an array of arrays – jagged by definition. There’s nothing to say it’ll stay rectangular forever, or even that all the elements of the “top-level” array will be non-null.

    I’d expect the values to start off close to each other in memory, but there’s no guarantee that they’d stay that way.

    If you really want to make sure you have a contiguous block of memory, you should use int[] x = new int[40]; instead.

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

Sidebar

Related Questions

This topic can look similar to others but I haven't found any usable answer
I have found couple of similar topic about this but none of them solve
I've found plenty of other topics similar to this one, but I they are
I've found this topic for PostData using http. but it doesn't work. What's wrong?
I've found this topic which I've implemented (see accepted answer): javascript equivalent of PHP's
This topic has been covered on this forums, but I haven't found a working
I've found some questions here about this topic, but none of the solutions solve
i know every web-developer hates this topic, but anyway... i found no good solution
I found a topic on MSDN that talks that yes, this is possible. I
I know this is a recurrent/classical topic but I did not found anything that

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.