title: Converting a .txt file to a 2D arraylist of strings
body: <p>So I'm trying to convert a .txt file in the format of</p>
  
  <pre><code>1 2 3 4 
  5 6 7 8
  9 1 0 1
  </code></pre>
  
  <p>into a 2D arraylist of strings. 
  This should also be replicable with any other thing such as</p>
  
  <pre><code>EXTENDING RETRACTING RETRACTING EXTENDING
  EXTENDING EXTENDING RETRACTING
  RETRACTING
  </code></pre>
  
  <p>Here's my code</p>
  
  <pre><code>public class Test {
      public static ArrayList&lt;ArrayList&lt;String&gt;&gt; readFromFile(String path) throws FileNotFoundException{
          @SuppressWarnings("resource")
          Scanner in = new Scanner(new File(path));
          ArrayList&lt;ArrayList&lt;String&gt;&gt; comments= new ArrayList&lt;ArrayList&lt;String&gt;&gt;();
          ArrayList&lt;String&gt; words = new ArrayList&lt;String&gt;();
          String[] line;
          String str;
          String [] values;
          while(in.hasNextLine()){
              str=in.nextLine();
              line = str.split("\t");
              values = line[2].split(" ");
              for(String word : values){
                  words.add(word);
              }
          }
          comments.add(words);
          return comments;
          }
  
      public static void main(String[] args) throws FileNotFoundException{
           ArrayList&lt;ArrayList&lt;String&gt;&gt; inputs = readFromFile("/Users/Jason/yaw.txt");
          int k = 0;
          for(int i = 0; i &lt; inputs.size(); i++){
              for(int j = 0; j &lt; inputs.get(k).size(); j++){
                  System.out.print(inputs.get(i).get(j));
                  k++;
              }
              System.out.println();
          }
      }
  }
  </code></pre>
  
  <p>Currently, it returns this error.</p>
  
  <pre><code>Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
      at Test.readFromFile(Test.java:19)
      at Test.main(Test.java:31)
  </code></pre>
  
  <p>Any help on how to get this working?</p>