Variable-sized Array Initialization in Java
arrays, initialization, java
Solution
int[] myNumbers = new int[size];
Arrays.fill(myNumbers, 0);
see http://java.sun.com/j2se/1.5.0/docs/api/java/util/Arrays.html
Problem
I have an array of integers in Java that is initialized as follows: ``` public int MyNumbers[] = {0,0,0,0}; ``` I would like to, however, initialize the array to a variable-length number of zeroes. ``` private int number_of_elements = 4; public int MyNumbers[] = {0} * number_of_elements; // ???? ``` I am clueless how to do this being new to Java coming from C. Any suggestions? EDIT I know I could use a `for` loop, but I hoping there was a simple way to do it.