title: Java - ordering/alphabetizing Array of strings
body: <p>I have a project in my comp 182 class we're working on vectors but I'm stuck on making an "ordered vector". When I try to run it I get an ArrayOutofBounds error.
  <br><br>
  (The "howMany" variable is the count for the size of the Strings in the array "theWords"<br>
  And the code is run from another class that reads an input file with 10 words in it,using this "addWord" method to add the words from the file into the "theWords" array.)
  <br><br>Here's the code I have so far: <br>[btw we're not allowed to use the "Array" methods only "compareTo"]</p>
  
  <pre><code> public void addWord(String newWord) {
    //adds in words
       if (howMany &lt; theWords.length) {
          theWords[howMany]= newWord; 
          howMany++;
       }  
       else {
          String t [] = new String[capacity+10];
          for (int i=0; i &lt;capacity; i++){
             t[i] = theWords[i];
          }
          theWords = t;
          theWords[howMany] = newWord; 
          howMany++;
       }
  
      //ordering words
       for(int g = howMany - 1, z = howMany ; g &lt; howMany; g--, z--) {
          if(newWord.compareTo(theWords[g]) &lt; 0) {
             theWords[g] = theWords[z];
             theWords[g] = newWord;
          }
              else
              newWord = theWords[z];          
       }
          howMany++;
    }
  </code></pre>
  
  <p>Any help is much appreciated! </p>