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