In java you have to set the size of the Array when you create it
int[] arr = new int[2];
Then once the array is created, you can add values to a specific index like this:
arr[0] = 3;
arr[1] = 4;
//Now arr = {3, 4}
However, you cannot add a third value to the array arr because the size is fixed at 2. If you need to change the size of the array, an ArrayList would be better. You can just use the add() method and it will add values to the end of the array
ArrayList<Integer> arr = new ArrayList<Integer>();
arr.add(3);
arr.add(4);
arr.add(5);
//Now arr contains the values {3, 4, 5}
//You can continue you add values
EDIT: Another option is to use the Arrays.copyOf(int[] arr, int size)
int[] arr = {3, 4};
//arr contains the values {3, 4}
int[] arr2 = Arrays.copyOf(arr, 4);
//arr2 contains the values {3, 4, 0, 0}
ArrayList<T>.ArrayList, in which you can preallocate however much space you want and let the library manage it for you.