# 3 steps to make an array

Three steps are required to create an array.

1. Declare variables in the array
2. Create elements of the array
3. Substitute a value

As an image

1. Make a large box (array variable)
2. Make a partition (array element) in the box
3. Put a thing (value) in the partition

Such a place.

## 1. Declare variables in the array

To declare an array variable, write as follows.

``````Array element data type[]Variable name of array;
``````

The data type of an array element is the data type of the element to be assigned in the array. An integer is int [], a decimal is double [], and a string is String [].

The variable name of the array is basically the English plural that represents the contents of the array. Scores if the contents of the array are the numbers of the test scores, colors if the string of the color name, etc.

Example: Define an array of integers numbers

``````//Since it is an integer, the data type is int, after the data type[]Define with
int[] numbers;
``````

## 2. Create element

To assign an element, write as follows.

``````Variable name of array=Data type of new element[Number of elements];
``````

Create an array element for the variable declared earlier.

The data type of the element is the same as the data type when the variable is declared. The number of elements is the number of values you want to put in the array.

Example: Assign three elements to the array numbers defined earlier

``````//Since numbers is an array of integers, the data type is int
//Since there are three elements, the number of elements is
numbers = new int;
``````

## 3. Assign value

To assign a value to an array, write as follows.

``````Variable name of array[index number] =Value you want to assign;
``````

Example: Substitute the integers 10, 20, 30 for numbers

``````//Note that the index number starts from 0
numbers = 10;
numbers = 20;
numbers = 30;
``````

After creating the elements of the array, if the value is not entered, the value is automatically assigned according to the data type when compiling. (0 for int, null for String, etc.)

# Describe array creation and value assignment together

If you create an array by following the above 3 steps, it will be as follows.

Example: Create an array of integers, assign numbers 10, 20, 30

``````//Declare a variable
int[] numbers;

//Create element
numbers = new int;

//Assign value
numbers = 10;
numbers = 20;
numbers = 30;
``````

However, these can also be described together as follows.

``````Array element data type[]Variable name of array= {Value 1,Value 2,Value 3, ...};
``````
``````//Example: Make an array of integers numbers and integer 10, 20,Substitute 30
int[] numbers = {10, 20, 30};
``````