You are not adding values to the array, you are replacing it.
int[] arr = new int[5]; --> int[] arr = [0,0,0,0,0] arr = [1,2,3,4,5,6]; --> int[] arr = new int[] {1,2,3,4,5,6}