Class 3++++
Class 3++++
Array
Two-dimensional array
Tablicy (array)
● An array is a special object in which you can store
not one value, but multiple values.
● In such an object there are several cells, each of
which can be accessed by its number (index)
starting from zero.
● To do this, after the name of the array variable in
square brackets, you need to specify the index of
the cell to which we access:
array[index] = value;
array - name of the array variable
index - cell number in the array
value - the value that we want to put in a specific
cell
Creating an array of elements in Java
If we want to store 100 integers, we need an
array of type int:
int[] array = new int[100];
Declaration of a array variable with type int. The
int type is followed by square brackets [], which
indicates that you can store not one value, but
multiple values. On the right side of the “=” sign
we have written “new” for creating array of 100
elements of type int.
Create an array of 20 elements to store real
(double) numbers:
double[] vals = new double[20];
The number of cells in an array is called
the array size or array length. And
because of the ability to store multiple
values, arrays are also called
containers.
Code Explanation
Code Explanation
In matrix [0] we store the reference to
the first row.
int[][] matrix = {
{1, 2, 3, 4, 5},