Arrays in Java

An array is a special variable or container object. Unlike a variable holding just one value, an array can hold multiple values in a single type array container. All elements in an array have numeric index which is used to acces their element value.

first index second third fourth fifth sixth seventh last index
0 1 2 3 4 5 6 7 indices/keys
“zero” “one” “two” “three” “four” “five” “six” “seven” elements/values


Here we have declared an integer array:

and allocate a memory for the elements:

at the end we have assigned the initial values started from zero up to eight.

Accessing the values of an array

In this example things might look different from the above example we sow but it is just another way of declaring, allocating and initializing array’s.



The example will printout the index values of zero on the screen. And we can do so for any element or index we want to access in our program.

Array of Arrays

Array of arrays or so called multidimensional array. An array which is, its components are arrays. An element should be accessed by a corresponding number of indexes



Here we have declared and assigned the multidimensional string type array in order to access its corresponding values as an index value.

Leave a Reply

Your email address will not be published. Required fields are marked *