Results 1 to 5 of 5

Thread: Regarding multidimentional array

  1. #1

    Thread Starter
    Member upstream's Avatar
    Join Date
    Jun 2007
    Location
    Philippines
    Posts
    48

    Talking Regarding multidimentional array

    Hey, how can i declare and assign a value from one, or both of of it's dimension in a multidimentional array?

    starting to this:

    Code:
    String[][] GroupList = new String[5][5];
    ??

    i've got a book, but it's only a quick summary =/, thanks uhm, and please give me at least an example...

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Regarding multidimentional array

    You mean something like this:
    Code:
    	String[][] GroupList = new String[5][5];
    	GroupList[0][0] = "List1 Item1";
    	for (int i = 0; i < GroupList.length; i++) {
    	    for (int j = 0; j < GroupList[i].length; i++) {
    		GroupList[i][j] = "List" + i + " Item" + j;
    	    }
    	}
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3

    Thread Starter
    Member upstream's Avatar
    Join Date
    Jun 2007
    Location
    Philippines
    Posts
    48

    Re: Regarding multidimentional array

    ok thanks po...i'll try the code later XD

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Regarding multidimentional array

    On a pedantic note, Java doesn't support true multidimensional arrays. What you have there is instead a jagged array.

    A multidimensional array is stored contiguously, such that, when given given the number and size of the array dimensions, any item in the array can be found using a single pointer expression.

    A jagged array is a one-dimensional array of references to other arrays.
    Because Java doesn't have pointers, a jagged array, for all intents and purposes, can be considered behaviourally equivalent to a multidimensional array. However, it will not exhibit the same linear performance as a true multidimensional array; the speed of accessing a jagged array is dependent on the level of nesting, since one extra indirection is required per "dimension".
    On the positive side, though, they are more flexible, and can be quicker for certain tasks (such as moving columns within the array, which can be accomplished by merely swapping references).

  5. #5
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Regarding multidimentional array

    Thanks for the note
    I found a good article and I'd like to share it with everyone
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

Posting Permissions

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



Click Here to Expand Forum to Full Width