Results 1 to 5 of 5
  1. #1
    Aboogesnickle is offline Member
    Join Date
    Jun 2014
    Posts
    12
    Rep Power
    0

    Question what is the difference between regular arrays and multi- dimensional arrays?

    I mainly would like to know is a int[4][4] or a int [4*4] is more efficient to use. Which takes more storage? Which requires more to process? that kind of stuff. Any answer or links to reading material that might help would be appreciated.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default Re: what is the difference between regular arrays and multi- dimensional arrays?

    To see what code is generated to handle those two arrays, write a small test program and use the javap program to show the bytecode that was generated. That may show some differences.

    Worrying about those kinds of efficiency can be a waste of time at this stage of learning.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,930
    Rep Power
    5

    Default Re: what is the difference between regular arrays and multi- dimensional arrays?

    Quote Originally Posted by Aboogesnickle View Post
    I mainly would like to know is a int[4][4] or a int [4*4] is more efficient to use. Which takes more storage? Which requires more to process? that kind of stuff. Any answer or links to reading material that might help would be appreciated.
    Actually, it depends on what you want to do and what facilitates writing the program. Using one of the List implementations like ArrayList is more preferable that using an array as they are easier to manipulate. And if you want 2D arrays, you can use a list of lists. And yet, ArrayList implementations have quite a bit more overhead than regular arrays as they are java classes and regular arrays are handled by the JVM. But the difference is usually minimal and worth the tradeoff in terms of functionality.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #4
    Aboogesnickle is offline Member
    Join Date
    Jun 2014
    Posts
    12
    Rep Power
    0

    Default Re: what is the difference between regular arrays and multi- dimensional arrays?

    I am using the arrays to hold pixel data and the 2d array and one twice as long array is about the same to manipulate, so i was just wondering if there was big difference since either can be used. I do know really know that much about ArrayList, so i will have to look into that. Thanks for your replies.

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,930
    Rep Power
    5

    Default Re: what is the difference between regular arrays and multi- dimensional arrays?

    One thing you need to understand about multi-dimensional arrays in Java. That is, they don't exist! A 2D array is nothing but a 1D array of references. And those references are to other 1D arrays. So this allows you to have asymmetrically sized "2D" arrays since each reference may point to an array of arbitrary length.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Replies: 4
    Last Post: 03-09-2011, 06:54 AM
  2. Replies: 4
    Last Post: 08-01-2010, 10:25 AM
  3. Multi-dimensional arrays
    By Implode in forum New To Java
    Replies: 1
    Last Post: 09-15-2009, 09:50 AM
  4. [SOLVED] Multi-dimensional arrays
    By thelinuxguy in forum Advanced Java
    Replies: 3
    Last Post: 05-07-2009, 03:52 PM
  5. Replies: 2
    Last Post: 01-07-2008, 08:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •