Arrays.fill() - ArrayIndexOutOfBoundsException
Solution 1:
Read the corresponding java doc: the 3rd parameter is the last index to fill. So the method "fills" from the first given index to that index -1
So you have to pass the indexes you care about, not the current content at those indexes!
Arrays.fill(nums, 0, size-1 ,0);
And note, the exception messages would have told you that you tried to access an invalid index. So the real answer is: read the exception messages carefully, and: read the javadoc for the library calls you are using even more carefully.
Solution 2:
The ArrayIndexOutOfBoundsException Happens when the developer call index is not found in the array, so I have checked the size of the array and Marco needs to set all values of the array zeros except the last one. the method fill works like this => Arrays.fill( ARRAY,FIREST_INDEX, LAST_IDNEX,VALUE) ;
public static int[] makeLast(int[] nums) {
int size = nums.length;
if (size != 0) {
Arrays.fill(nums, 0, size - 1, 0);
}
return nums;
}