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 ww.  j  a va  2s  .c  o  m*/
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.