Fill to a sub range of elements in a char type array in Java
Description
The following code shows how to fill to a sub range of elements in a char type array.
Example
// ww w .ja va 2 s. c o m
import java.util.Arrays;
public class Main {
public static void main(String[] argv) throws Exception {
int startIndex = 0;
int endIndex = 4;
char[] charArr = new char[10];
char charFillValue = 1;
System.out.println(Arrays.toString(charArr));
Arrays.fill(charArr, startIndex, endIndex, charFillValue);
System.out.println(Arrays.toString(charArr));
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »