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








Syntax

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

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

Example

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

/*from   www  .  j a v  a2 s.c om*/
import java.util.Arrays;

public class Main {

  public static void main(String[] args) {
    
    // initializing Object array
    Object arr[] = new Object[] {1.5, 5.6, 4.5, 2.3, 6.7};
    
    System.out.println(Arrays.toString(arr));

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

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

The code above generates the following result.