2
2
.
.
6
6
.
.
1
1
a
a
r
r
r
r
a
a
y
y
I
I
n
n
f
f
o
o
Array can't be resized. To change array size create new one and transfer elements or use ArrayList, Vector, etc.
Array can only contain Elements of the same Data Type: just int, just String, Objects of the same Class.
1D
//DECLARE.
int[] array; //Declared. Used to define scope.
int[] array = null; //Declare empty Array.
int[] array = new int[5]; //Declare Array with default values: 0, 0.0, false, null.
int[] array = {0,1,2,3}; //Declare Array with specific values.
String[] array = {"John", "Lucy"}; //Declare Array os Strings.
//OTHER.
int length = array.length; //Number of elements
System.out.println(Arrays.toString(array)); //Display Array [0, 1, 2, 3]
array[0] = 5; //Modify element at index 0.
int element = array[0]; //Get element at index 0.
2D
//DECLARE.
int[][] array; //Declared. Used to define scope.
int[][] array = null; //Declare empty Array.
int[][] array = new int[2][4]; //Declare Array with default values: 0, 0.0, false, null
int[][] array = { //Declare Array with specific values
{0,1,2,3}, //array[0] = {0,1,2,3} array[0][2] = 2
{4,5}, //array[1] = {4,5} array[1][0] = 4
{6,7,8,9} //array[2] = {6,7,8,9} array[2][3] = 9
};
//OTHER.
int length = array.length; //Number of elements
System.out.println(Arrays.toString(array)); //Display Array [0, 1, 2, 3]
array[2][3] = 90; //Modify element in Array/Row 2 at index 3
int element = array[2][3]; //Get element in Array/Row 2 at index 3
3D
//DECLARE.
String[][][] multyArray =
{
//Table 0
{
{"000","001"}, //Row 0
{"010","011","012","013"} //Row 1
},
//Table 1
{
{"100","101","102","103"}, //Row 0
{"110","111"} //Row 1
}
};
//OTHER.
multyArray[0][1][3] = "013"; //Modify element from Table 0, Row 1, index 3
String element = multyArray[0][1][3]; //Get element from Table 0, Row 1, index 3