Java Programming/Arrays

About Arrays
An array is a group of variables of the same data type and referred to by a common name. An array is contiguous block of memory locations referred by a common name.

i.e. To store 500 integer values in the variable multipleInt, you type this.

One-dimensional arrays
One-dimensional array is a list of variables of the same data type.

Syntax to declare a one dimensional array
You can also declare and initialize arrays in the same statement.

For e.g.

Things you can do with arrays
You can print out all the values in the array. For e.g.

A possible output of the above will be:

20

2 4 13 6 18 12 14 10

Notice this part of the code Notice that in this part of that code:  , the variable fillUp must be one less the length of the array. Why do we have to do this? You may ask. Remember, the index 0 is the first value in an array/String. So if the length was 11, and the program searched for the 12th value, it would not find it, and there would be an error that says something like this: Index Out of Range.

Two-dimensional arrays
To declare two-dimensional arrays, you need to specify multiple square brackets after the array name.

Other Types of Arrays
You can also declare arrays like but it will make programming with these arrays very complicated.

The 1 dimensional array and the 2 dimensional arrays are the most commonly used