Fill to a sub range of elements in a String type array in Java
Description
The following code shows how to fill to a sub range of elements in a String type array.
Example
/*from www. j a v a2 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;
String[] stringArr = new String[10];
String stringFillValue = "1";
System.out.println(Arrays.toString(stringArr));
Arrays.fill(stringArr, startIndex, endIndex, stringFillValue);
System.out.println(Arrays.toString(stringArr));
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »