Results 1 to 4 of 4

Thread: How to implement MultiDimensional Array in JAVA

  1. #1
    Join Date
    Feb 2009
    Posts
    40

    How to implement MultiDimensional Array in JAVA

    Hello Programming Gurus,

    I am newbie to the Multidimensional Array topic in JAVA it has alway been difficult for me to understand so think here i will get some help.
    So can anybody suggest how should i implement Multidimensional Array in JAVA, explain me with some example.

    Regards,

  2. #2
    Join Date
    Jan 2009
    Posts
    108

    Re: How to implement MultiDimensional Array in JAVA

    Here i will explain you with the small example on MultiDimensional Array in JAVA
    please have a look at it.

    Code:
    int[][] a2 = new int[10][5];
    // print array in rectangular form
    for (int r=0; r<a2.length; r++) {
         for (int c=0; c<a2[r].length; c++) {
             System.out.print(" " + a2[r][c]);
         }
         System.out.println("");
    }

  3. #3
    Join Date
    Jan 2009
    Posts
    99

    Re: How to implement MultiDimensional Array in JAVA

    A multi-dimensional array of dimension n (i.e., an n-dimensional array or simply n-D array) is a collection of items which is accessed via n subscript expressions. For example, in a language that supports it, the tex2html_wrap_inline60030 element of the two-dimensional array x is accessed by writing x[i,j].

    The Java programming language does not really support multi-dimensional arrays. It does, however, support arrays of arrays. In Java, a two-dimensional array x is really an array of one-dimensional arrays:

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

    The expression x[i] selects the tex2html_wrap_inline57420 one-dimensional array; the expression x[i][j] selects the tex2html_wrap_inline59650 element from that array.

    The built-in multi-dimensional arrays suffer the same indignities that simple one-dimensional arrays do: Array indices in each dimension range from zero to tex2html_wrap_inline59952, where length is the array length in the given dimension. There is no array assignment operator. The number of dimensions and the size of each dimension is fixed once the array has been allocated.

  4. #4
    Join Date
    Jan 2009
    Posts
    163

    Re: How to implement MultiDimensional Array in JAVA

    The type-signatures and constructors of the multidimensional array use double brackets to distinguish them from ordinary arrays:

    int [[,]] a = new int [[5, 5]] ;

    float [[,,]] b = new float [[10, n, 20]] ;

    int [[]] c = new int [[100]] ;

    a, b and c are respectively 2-, 3- and one- dimensional arrays. Of course c is very similar in structure to the standard array d, created by

    int [] d = new int [100] ;

    c and d are not identical, though3.

    Accessing individual elements of a multidimensional array goes through a subscripting operation involving single brackets

    for(int i = 0 ; i < 4 ; i++)
    a [i, i + 1] = i + c [i] ;

    For reasons that will become clearer in later sections, this style of subscripting is called local subscripting. In the current sequential context, apart from the fact that a single pair of brackest may include several comma-separated subscripts, this kind of subscripting behaves just like ordinary Java array subscripting. Subscripts always start at zero, in the ordinary Java or C style (there is no Fortran-like lower bound).

Similar Threads

  1. Implement Simple Database using BST in Java
    By maxmidg412 in forum Software Development
    Replies: 2
    Last Post: 31-07-2011, 03:22 AM
  2. Multidimensional ArrayList in java
    By Aaliya Seth in forum Software Development
    Replies: 6
    Last Post: 16-02-2011, 01:03 AM
  3. Multidimensional ArrayList in Java
    By Navp in forum Software Development
    Replies: 1
    Last Post: 05-02-2011, 12:43 AM
  4. Implement the return type in java
    By Captain Carrot in forum Software Development
    Replies: 4
    Last Post: 25-03-2010, 01:34 PM
  5. Implement Java tic tac toe
    By SmokiN in forum Software Development
    Replies: 3
    Last Post: 29-06-2009, 09:09 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,717,382,797.88250 seconds with 16 queries