Define a static method to fill an array of type char[] with a given value passed as an argument to the method.
Output of Above Java Program
The array contains: ZZZZZZZZZZZZZZZZZZZZ
import java.util.Arrays;
public class FillArray {
public static void fill(char[] array, short value) {
java.util.Arrays.fill(array, (char)value);
}
public static void main(String[] args) {
char[] chars = new char[20];
short value = 90; // This is equivalent to 'Z'
fill(chars, value);
System.out.print("The array contains: ");
for(char ch : chars) {
System.out.print(ch);
}
}
}
Output of Above Java Program
The array contains: ZZZZZZZZZZZZZZZZZZZZ