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








Syntax

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

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

Example

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

/* w w  w . j a  v a  2s. c o m*/

import java.util.Arrays;

public class Main {

  public static void main(String[] args) {
    
    boolean arr[] = new boolean[] {true, true, false};

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

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

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

The code above generates the following result.