title: java.lang.ArrayIndexOutOfBoundsException: 4
body: <p>I am working on extracting values from a tab separated text file into a list in groovy. But am running into the <code>ArrayIndexOutOfBoundsException</code>. </p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>println("Reading File Contents")
  
  def fullArray = new String[31721][4]
  def availableArray = new String[1386][2]
  def filteredFullArray = new String[1386][5]
  
  String fileContents = new File('beliefs.txt').text
  String availableContents = new File('available.txt').text
  
  def count = 0
  
  fileContents.eachLine { line -&gt;
  
      String[] str
      str = line.split('\t')
  
      def subCount = 0
      for (subCount; subCount &lt; str.length; subCount++) {
           fullArray[count][subCount] = str[subCount]
      }
      count++
  }
  </code></pre>
  
  <p><strong>beliefs.txt</strong></p>
  
  <pre><code>1   Azerbaijan  hasOfficialLanguage Azerbaijani_language
  2   Augustus    hasChild    Julia_the_Elder
  3   Arthur_Aikin    isCitizenOf England
  4   Arthur_Aikin    diedIn  London
  5   Alexander_III_of_Russia isMarriedTo Maria_Feodorovna__Dagmar_of_Denmark_
  6   Alexander_III_of_Russia hasChild    Nicholas_II_of_Russia
  7   Alexander_III_of_Russia hasChild    Grand_Duke_Michael_Alexandrovich_of_Russia
  8   Alexander_III_of_Russia hasChild    Grand_Duchess_Olga_Alexandrovna_of_Russia
  9   Alexander_III_of_Russia hasChild    Grand_Duke_Alexander_Alexandrovich_of_Russia
  10  Alexander_III_of_Russia hasChild    Grand_Duke_George_Alexandrovich_of_Russia
  ...
  ...
  ...
  31719   Minqi_Li    isKnownFor  Chinese_New_Left
  31720   Henry_Bates_Grubb   isKnownFor  Mount_Hope_Estate
  31721   Thomas_Kuhn isKnownFor  Paradigm_shift  
  </code></pre>
  
  <p>Running this gives me the following error.</p>
  
  <blockquote>
    <p>Caught: java.lang.ArrayIndexOutOfBoundsException: 4
    java.lang.ArrayIndexOutOfBoundsException: 4
        at extractBeliefs$_run_closure1.doCall(extractBeliefs.groovy:19)
        at extractBeliefs.run(extractBeliefs.groovy:12)</p>
  </blockquote>
  
  <p>I am aware of the reason why the above error could occur. But since my array does not exceed the last index and since the error is shown to be at the line <code>fileContents.eachLine { line -&gt;</code>, I am unable to find where this is going wrong.</p>
  
  <p>Any suggestions in this regard will be highly appreciated.</p>