Arrays.fill and copyOf
Fill and resize arrays.
Filling Arrays
Arrays.fill sets every element of an array to the same value. It modifies the array in place and is handy for initializing or resetting data.
A Basic Fill
Fill an entire array with one value.
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
int[] nums = new int[5];
Arrays.fill(nums, 7);
System.out.println(Arrays.toString(nums));
}
}All lessons in this course
- Arrays.sort and Sorting
- Arrays.binarySearch
- Arrays.fill and copyOf
- Arrays.equals and toString