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


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

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


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

//from   w  w w . j  ava2 s  .  co  m
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};

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


The code above generates the following result.