muttley
Posts: 19
Joined: Thu Feb 28, 2013 9:47 am
Contact:

I think that in this sentence:
daaa[0] should be a 2 dimensional array because daaa is a 3 dimensional array.
You meant:
d should be a 2 dimensional array because daaa is a 3 dimensional array.
Right?

Posts: 7593
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

### Re: About Question enthuware.ocajp.i.v7.2.1307 :

Yes, you could say it that way. Assuming that you are talking about option 1, what ever you assign to daaa[0], should be a 2 D array. But d is not a 2 D array. So the assignment is invalid.

lordnovas
Posts: 12
Joined: Tue Jan 15, 2013 3:31 pm
Contact:

### Re: About Question enthuware.ocajp.i.v7.2.1307 :

Hey quick question:

What is the rule(s) concerning assigning values to 2D/3D array elements? What I currently see is that if you have a 3D array then you must use a 2D array to assign a value to an element within the 3D array, however I'm not sure why?

Is it because a 2D array can fit into a 3D array, or is it because of the array type, like a 2D array can fit into a 3D array?

Posts: 7593
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

### Re: About Question enthuware.ocajp.i.v7.2.1307 :

Consider this. If you have a one dimensional array of ints (i.e. int[] ia), what would each element be? An int, right?

So if you have a two dimensional array of ints (i.e. int[][]) , which basically means an array or array of ints i.e. a 2D array, what would be the type of the first element of the top most array?

By the way, you should not talk of Java arrays in dimensions because arrays are not like matrix in java. In other words, Java arrays are not necessarily symetrical like a rectangular matrix. They are jagged. You should talk of them in terms of arrays of arrays of arrays...

You should read about it from a book because it is too much to explain in a forum.

lordnovas
Posts: 12
Joined: Tue Jan 15, 2013 3:31 pm
Contact:

### Re: About Question enthuware.ocajp.i.v7.2.1307 :

Ahhh, I get it. I think my approach/language was flawed. To insure I have it down below is my description for the arrays. Is that language better. I'm currently using the OCA Java7 study guide, and all of my Java training has been self taught, which is probably why I ask the dumbest questions - but please bare with me.

This is an integer Array, that stores integer values.

Code: Select all

``int[] a;``
This is a 2D Array, that stores an Array of integer Arrays

Code: Select all

``int[][] b;``
This is a 3D Array of type int, that stores an Array of 2D Arrays of type integer

Code: Select all

``int[][][] c;``

Posts: 7593
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

### Re: About Question enthuware.ocajp.i.v7.2.1307 :

correct.

lordnovas
Posts: 12
Joined: Tue Jan 15, 2013 3:31 pm
Contact:

### Re: About Question enthuware.ocajp.i.v7.2.1307 :

Awesome thanks again.

gwake1
Posts: 1
Joined: Tue Mar 13, 2018 7:51 pm
Contact:

### Re: About Question enthuware.ocajp.i.v7.2.1307 :

int[] d1 = new int[]{};

int[][]d2 = new int[][]{};

int [][] d2Demo = new int[][]{new int[]{}};

int[][][] d3 = new int[][][]{};

int[][][]d3Demo = new int[][][]{new int[][]{new int[]{}}};

int [][][] d3MindBlown = new int[][][]{ d2 = new int[][]{ d1 = new int[]{} } };

### Who is online

Users browsing this forum: bortnikov_sa@mail.ru and 17 guests