MrPork
MrPork

Reputation: 75

What does it mean when an integer is declared like this?

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?

Upvotes: 0

Views: 144

Answers (6)

kar
kar

Reputation: 3651

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};

Upvotes: 2

Sabuj Hassan
Sabuj Hassan

Reputation: 39355

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.

Upvotes: 2

La-comadreja
La-comadreja

Reputation: 5755

It's a three-dimensional matrix of integers.

Upvotes: 1

Vivek Vermani
Vivek Vermani

Reputation: 2004

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.

Upvotes: 1

James World
James World

Reputation: 29776

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

Upvotes: 1

Robert Harvey
Robert Harvey

Reputation: 180777

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

Upvotes: 9

Related Questions