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








Syntax

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

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

Example

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

//from   w w  w .  ja  v  a  2 s.c  o m


import java.util.Arrays;

public class Main {

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

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

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

The code above generates the following result.