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