Java Arrays FillBy using the Arrays.fill() method, we can either fill a complete array or can fill some part of it. Arrays.fill() method is also capable of filling both the 2D and the 3D Arrays. Arrays fill() method has the following syntax: Here,
Let's take some examples to understand how we can use the Arrays.fill() method for filling array. Fill entire 1-D ArrayArraysFillExample1.java Output: ![]() Fill some part of 1-D ArrayArraysFillExample2.java Output: ![]() Fill multidimensional array (2D Array)Just like a single-dimensional array, we can also fill the multidimensional array by using the Arrays.fill() method. In order to fill a multidimensional array, we use the for loop to fill each row of the multidimensional array. Let's take an example to understand how we can fill a multidimensional array using the Arrays.fill() method. ArraysFillExample3.java Output: ![]() ArraysFillExample4.java Output: ![]()
Next TopicJava Font
|