Java Arrays.fill(int[] a, int val)

Syntax

Arrays.fill(int[] a, int val) has the following syntax.

public static void fill(int[] a, int val)

Example

In the following code shows how to use Arrays.fill(int[] a, int val) method.


/*from ww  w  .  ja  v  a2  s.c  om*/
import java.util.Arrays;

public class Main {

  public static void main(String[] args) {
    
    // initializing int array
    int arr[] = new int[] {1, 2, 3, 4, 5};
    
    System.out.println(Arrays.toString(arr));

    // using fill for placing 8
    Arrays.fill(arr, 8);

    System.out.println(Arrays.toString(arr));
  }
}

The code above generates the following result.