declare a variable of the desired array type.
allocate the memory using new.
In Java all arrays are dynamically allocated.
You can access a specific element in the array with [index].
All array indexes start at zero.
For example, the following code assigns the value 28 to the second element of days.
public class Main {
public static void main(String[] argv) {
int days[];
days = new int[12];
days[1] = 28;
System.out.println(days[1]);
}
}
It is possible to combine the declaration of the array variable with the allocation of the array itself.
int month_days[] = new int[12];