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








Syntax

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

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

Example

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

/*w w  w  .  jav  a2 s .c  om*/
import java.util.Arrays;

public class Main {

  public static void main(String[] args) {
    
    // initializing char array
    char arr[] = new char[] {'a','b','c'};
    
    System.out.println(Arrays.toString(arr));

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

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

The code above generates the following result.