title: How can we dynamically allocate and grow an array
body: <p>I am working on a project, but I cannot use any existing java data structures (ie, ArraysList, trees, etc)</p>
  
  <p>I can only use arrays. Therefore, I need to dynamically update an array with new memory.</p>
  
  <p>I am reading from a text file, and I pre-allocate 100 for the arrays memory:</p>
  
  <pre><code>   String [] wordList;
     int wordCount = 0;
     int occurrence = 1;
     int arraySize = 100;
     wordList = new String[arraySize];
     while ((strLine = br.readLine()) != null)   {
           // Store the content into an array
           Scanner s = new Scanner(strLine);
           while(s.hasNext()) {
             wordList[wordCount] = s.next();
             wordCount++;
           } 
     }
  </code></pre>
  
  <p>Now this works fine for under 100 list items. br.readline is the buffered reader going through each line of a textfile. I have it then store each word into list and then increment my index (wordCount).</p>
  
  <p>However, once I have a text file with more than 100 items, I get an allocation error.</p>
  
  <p>How can I dynamically update this array (and thereby sort of reinvent the wheel)?</p>
  
  <p>Thanks!</p>