Initializing an object in an array with a default value - java
<p>Is there a way to define a default value for an object in array to be initialized with?</p>

<p>In the same way that primitive types are initialized when declaring an array of them:</p>

<pre><code>int[] myIntArray = new int[5]; // we now have an array of 5 zeroes
char[] myCharArray = new char[2]; // an array in which all members are "\u0000"
</code></pre>

<p>etc.</p>

<p>I'd like to declare an array of objects of a type that I've defined, and have them automatically initialize in a similar fashion.
I suppose this would mean I'd like to run <code>new myObject()</code> for each index in the array (with the default constructor).</p>

<p>I haven't been able to find anything relevant online, the closest I got was to use <code>Arrays.fill(myArray, new MyObject())</code> after initializing the array (which actually just creates one object and fills the array with pointers to it), or just using a loop to go over the array and initialize each cell.</p>

<p>thank you!</p>

<p>EDIT: I realized this is relevant not just to arrays, but for declaring objects in general and having them default to a value / initialize automatically.</p>