Length of Multidimensional Arrary

Discussion in 'Java' started by Asad Kazmi, Jun 20, 2004.

  1. Asad Kazmi

    Asad Kazmi Guest

    hi,

    I want to know that in multidimensional array lenght of array is calculated
    like this procedure or any other

    Test[x][y] row (x)+column(y) = z Is this correct ?

    Regards
    Asad Kazmi
    Asad Kazmi, Jun 20, 2004
    #1
    1. Advertising

  2. Asad Kazmi

    VisionSet Guest

    "Asad Kazmi" <> wrote in message
    news:...
    > hi,
    >
    > I want to know that in multidimensional array lenght of array is

    calculated
    > like this procedure or any other
    >
    > Test[x][y] row (x)+column(y) = z Is this correct ?
    >


    In Java there is no such thing as a multidimensional array.

    int[][] ints // is an array of arrays.

    Length can only ever be attributed to one of those arrays.

    So for int[][] x = new int[4][3];

    There are 4 arrays of length 3 and one array of arrays of length 4

    syntactically as:

    int length1 = x.length; // ==4
    int length2 = x.length[0]; // ==3
    int length2 = x.length[1]; // ==3
    int length2 = x.length[2]; // ==3

    Note that the arrays do not need to be all the same length:

    int[][] y = new int[4][];
    y[0] = new int[1];
    y[1] = new int[2];
    y[2] = new int[3];

    int length1 = y.length; // ==4
    int length2 = y.length[0]; // ==1
    int length2 = y.length[1]; // ==2
    int length2 = y.length[2]; // ==3

    HTH
    --
    Mike W
    VisionSet, Jun 20, 2004
    #2
    1. Advertising

  3. Asad Kazmi

    Asad Kazmi Guest

    Thanku Mike,


    <snip>

    > In Java there is no such thing as a multidimensional array.
    >
    > int[][] ints // is an array of arrays.
    >
    > Length can only ever be attributed to one of those arrays.
    >
    > So for int[][] x = new int[4][3];
    >
    > There are 4 arrays of length 3 and one array of arrays of length 4
    >
    > syntactically as:
    >
    > int length1 = x.length; // ==4
    > int length2 = x.length[0]; // ==3
    > int length2 = x.length[1]; // ==3
    > int length2 = x.length[2]; // ==3
    >
    > Note that the arrays do not need to be all the same length:
    >
    > int[][] y = new int[4][];
    > y[0] = new int[1];
    > y[1] = new int[2];
    > y[2] = new int[3];
    >
    > int length1 = y.length; // ==4
    > int length2 = y.length[0]; // ==1
    > int length2 = y.length[1]; // ==2
    > int length2 = y.length[2]; // ==3
    >
    > HTH
    > --
    > Mike W
    >
    >
    Asad Kazmi, Jun 20, 2004
    #3
  4. Asad Kazmi

    Roedy Green Guest

    On Mon, 21 Jun 2004 03:15:43 +0500, "Asad Kazmi" <>
    wrote or quoted :

    >I want to know that in multidimensional array lenght of array is calculated
    >like this procedure or any other
    >
    >Test[x][y] row (x)+column(y) = z Is this correct ?


    I don't understand your notation or your question.

    To understand how Java finds element [x][y] see
    http://mindprod.com/jgloss/matrix.html

    I acted this out several times at Colorado Conferences racing
    breathlessly around the room to demonstrate what a production it is.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
    Roedy Green, Jun 20, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jacob
    Replies:
    1
    Views:
    317
    Victor Bazarov
    Dec 23, 2004
  2. Mockey Chen

    why arrary with size of zero?

    Mockey Chen, Nov 21, 2005, in forum: C Programming
    Replies:
    2
    Views:
    319
    Clark S. Cox III
    Nov 21, 2005
  3. Nan Li

    sizeof arrary

    Nan Li, Oct 3, 2005, in forum: C++
    Replies:
    3
    Views:
    850
    Rolf Magnus
    Oct 3, 2005
  4. ottawajn

    variable size of an arrary

    ottawajn, Dec 8, 2006, in forum: C++
    Replies:
    7
    Views:
    392
    Default User
    Dec 8, 2006
  5. jacksu
    Replies:
    0
    Views:
    360
    jacksu
    Jul 13, 2007
Loading...

Share This Page