The revolutionary project management tool is here! Plan visually with a single glance and make sure your projects get done.

if 3 dimentional array how to get length of z axis(elements in z axis).

Any of below three works right.

data[][0].length

data[][1].length

data[][2].length

Any of below three works right.

data[][0].length

data[][1].length

data[][2].length

Those methods will work depending on exactly how the 3 dimensional array is created (there are some choices).

if data[0].length is greater than 2, then data[0][1].length and data[0][2].length could also work

Or another way to put it, is that the length of (what you are calling) the z axis, can be different at every different value of x and y.

Or if you consider the easier 2d situation first, the array doesn't need to be a regular rectangle of values, ie. the array DOES NOT have to look like this...

```
1 2 3 4 5
9 8 7 6 5
1 3 5 7 9
```

It is perfectly fine and valid to have a 2d array that looks like this

```
1 2 3 4 5
9 8 7
1 3 5 7 9 2 4 6 8 0
```

Now if you extend that to a 3rd dimension, (say there are values coming OUT of the page for each element above), then the number of elements (or the height coming out of the page) can be different for every different element above. (**And no, I'm not going to try and draw that! ;)

data[x][y][z]

any option to get all three lenghts(x, y and z axis lengths) using all 3 set of brackekes(first set[] , second set [], third set []) next to data to be consistent and easy to understand as below similar to how we get individual cell element.

1 2 3 4 5

9 8 7 6 5

1 3 5 7 9

3 5 6 7 8

data[x][][].length--->give

data[][y][].length--->give

data[][][z].length--->give

not sure on non symmetric examples like below where number of row element length varying from each row but i still fee data[x][][].length should give 3 as there are three rows eventhough second row only has 3 elements compared to first row which has 5 elements)

1 2 3 4 5

9 8 7

1 3 5 7 9 2 4 6 8 0

data.length = 3 // Since there are 3 rows

data[0].length = 5 // Since there are 5 elements in the first row (row 0)

data[1].length = 3 // Since there are 3 elements in the second row (row 1)

data[2].length = 10 // Since there are 10 elements in the third row (row 2)

Hopefully the above demonstrates why your idea of data[x][][].length (and the others) would not make much sense and why you need to be able to explicitly ask for which .length value that you want to query.

data[x][][].lengthis not valid syntax

data[x].length

returns a value only when x < data.length

data[][y][].lengthis not valid syntax

data[x][y].length

returns a value only when x < data.length && y < data[x].length

data[x][y].length

returns a value only when x < data.length && y < data[x].length

can you please elaborate on above

data[1][1].length what it returns

data[1][2].length what it returns

data[0][1].length what it returns

for below non symmetric example

1 2 3 4 5

9 8 7

1 3 5 7 9 2 4 6 8 0

please advise

{"1", "two", "3", "4", "5"},

{"9", "8", "7"},

{"1", "3", "5", "7", "9", "2", "4", "6", "8", "0"}

};

System.out.println("data[1

System.out.println("data[1

System.out.println("data[1

System.out.println("data[1

System.out.println("data[0

System.out.println("data[0

data[1][1] is "8"

data[1][1].length() is 1

data[1][2] is "7"

data[1][2].length() is 1

data[0][1] is "two"

data[0][1].length() is 3

All Courses

From novice to tech pro — start learning today.

declares that data[0][1] is a String

If data was declared differently, then data[0][1] could be of a different type.