0

I was doing a Tetris tutorial online, and noticed that there is an integer declared like this

int[][][] blah; 

Why does the integer have those 3 brackets?

2

6 Answers 6

9

It is a three-dimensional array.

Each set of brackets corresponds to an axis. Retrieving a value within the three-dimensional space looks something like this:

int value = blah[x][y][z]; 

Further Reading
Multi-Dimensional Arrays in Java

Sign up to request clarification or add additional context in comments.

1 Comment

Despite the 9 current up-votes, I have to ask is this really a three-dimensional array? As far as I can tell from the language specification, Java doesn't appear to have multi-dimensional array support, just support for one-dimensional arrays whose elements can be arrays. As are far as I can tell there is no restriction for member arrays to have a common length, so I say calling this an n-dimensional array is doubly misleading. I would call this an array of arrays of arrays, and add that it could be jagged. By programmatically ensuring it is not jagged, it can mimic a multi-dimensional array.
2

It means its a three dimensional array. It can hold the values like:

[ [1,2] [4,5] [2,3], [6,7], ] 

At above, each values are integer.

[1,2] is an array.

[1,2] [2,3] 

is a 2d array.

Comments

2

It is a 3-dimensional array as what has been said earlier.

You might want to start slow and understand what an array is before going into 3 dimensional. An array is declared as either one of the following ways. It can be used to hold a set of values of the same type (same type as in int, string and so on) instead of having to declare individual variables for each value.

int[] myArray = new int[5];

or

int[] myArray = {1,5,7,1,2};

Comments

1

It is a jagged array of integers - An array of arrays of arrays.

7 Comments

calling it "jagged" is misleading
Oh. Quick search showed this: xahlee.info/java-a-day/arrays2.html Is this rubbish?
According to this, arrays in Java seem to be jagged: docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html and the language spec isn't particularly clear, but looks like they are jagged: docs.oracle.com/javase/specs/jls/se7/html/jls-10.html.
This answer also claims Java arrays are jagged: stackoverflow.com/questions/5313832/…. Anyone have a definitive source?
Incidentally, the C# language has both jagged (declaration looks like Java) and rectangular (declaration looks like [,,] for a 3D array) arrays.
|
1

It's 3 dimensional array declaration. Such declarations are given because a[5] means something different in different dimensional arrays.So its a declaration to read the references properly.

Comments

1

It's a three-dimensional matrix of integers.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.