Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I fill a string array with empty objects?
    primarykey
    data
    text
    <p>So I create the array that will hold a cd collection. The only problem is the maximum array size is 50, how do I fill the array with empty objects if there's 50 objects?: </p> <pre><code>public static void main(String[] args) throws IOException { final int MAX_ARRAY_SIZE = 50; final String FILENAME = "Collection.txt"; CDOutput out = new CDOutput(); CDInput in = new CDInput(); int count = 0; // Counter to keep track of number of elements in the array int choice = 0; // Menu choice String[] songArray = new String[MAX_ARRAY_SIZE]; // Create array to hold song collection { songArray[0] = new String("");// Fill array with empty objects ???????? songArray[1] = new String(""); songArray[2] = new String(""); songArray[3] = new String(""); songArray[4] = new String(""); songArray[5] = new String(""); songArray[6] = new String(""); songArray[6] = new String(""); songArray[7] = new String(""); songArray[8] = new String(""); songArray[9] = new String(""); songArray[10] = new String(""); songArray[11] = new String(""); songArray[12] = new String(""); songArray[13] = new String(""); songArray[14] = new String(""); songArray[15] = new String(""); songArray[16] = new String(""); songArray[17] = new String(""); songArray[18] = new String(""); //and so on...... } </code></pre> <p>I know this cannot be correct...</p> <p>EDIT (this truly was quite easy in hindsight): </p> <pre><code>String[] songArray = new String[50]; for (int i = 0; i &lt; 50; i++) songArray[i] = new String(""); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload