


("Array before calling fill method: " + Arrays.toString(array)) 1.a : For 1-D array: Calling fill(int array, int value) import Let us understand using codes for each one of them. Here in this tutorial, we are going to apply fill() function on 1-D, 2-D, and 3-D arrays in Java. The only exceptions it throws is firstly, IllegalArgumentException – if fromIndex is greater than toIndex and secondly, ArrayIndexOutOfBoundsException – if fromIndex array.length. Secondly, it requires an array, an integer value of fromIndex, an integer value of toIndex and value, then it assigns that value to every element from fromIndex to toIndex indices in that array. Given are the two syntax for the function.įirstly, it requires an array and a value, then it assigns that value to every element in that array. Talking about fill() member function, this function has two syntax, basically, this function assigns a given value to each element in the array. This class contains various methods which are used to manipulate the data in Arrays data structure, for instance: sort() function sorts the array given to it, toString() function converts the data in the array to a string, similarly, equals() function compares two arrays of similar data types, etc. Understanding Arrays.Fill() in Java using different examples for the same.įirstly, Arrays is a pre-defined class in Java in its Util Package. Fill is a method of Arrays class in Java. In this tutorial, we will understand Arrays.fill() in Java.
