title: ArrayIndexOutOfBoundsException within Hardcoded Bounds
body: <p>Working on an assignment where I am supposed to read in data from a file into an array to do some search/sort demonstrations. </p>
  
  <pre><code>public class A5 {
  public static void main(String[] args) throws FileNotFoundException, IOException {
       fileToArray();
  }
   /**
   * populates array from file
   * @throws IOException
   * @throws FileNotFoundException
   */
  public static &lt;T extends Comparable&lt;T&gt;&gt; void fileToArray() throws IOException, FileNotFoundException {
      int FileIndex = 0;
  
      A5GItem[] gItems = new A5GItem[5150];
          File file = new File("GroceryData.txt");
          Scanner inputFile = new Scanner(file);
  
  
          while (inputFile.hasNext()) {
                  String line = inputFile.nextLine().replace(" oz", "").replace("«", "");
  
              String[] tokens = line.split(";");
              if (tokens.length == 5) {
  
              System.out.println(tokens[0]);
              System.out.println(tokens[1]);
              System.out.println(tokens[2]);
              System.out.println(tokens[3]);
              System.out.println(tokens[4]);
              System.out.println(FileIndex);
  
              FileIndex++;
              else {
                  System.out.println("Bad line: " + line);} 
                          }   }`
  </code></pre>
  
  <p>I tried to test whether I had filled the array properly by looping some println statements. It properly tokenizes the first 400(roughly) elements in the list and then only prints half of the last token and throws</p>
  
  <p><code>Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
      at A5.fileToArray(A5.java:59)
      at A5.main(A5.java:16)</code> </p>
  
  <p>after having run through with that index for many iterations. Not sure where to begin troubleshooting.</p>