Java One-Dimensional Array

One-dimensional array in Java is an array with a bunch of values that are declared with a single index. Here data are stored in a single column as shown below in an example.

Array declaration:

Example:

An array declaration has two components:
The type that is the data-type of an element and the name that is given by user choice with the brackets[].

Array initialization:

To initialize an array new is used and it appears as follows:

Example:

We can also set by combining declaration and initialization in the following ways:

Accessing an array element:

Array elements can be accessed by using its index number, where each element is assigned by one index number.
Example:

Example of a one-dimensional array:

Output: