title: Importing CSV file into 2D String array
body: <p>I have to read a text file into a 2d Array.</p>
  
  <p>The only problem I am having, is the width of the array varies, with a maximum size of 9 columns.
  I don't know how many rows there will be.</p>
  
  <p>Some lines will have 6 columns for example, and some will have 9.</p>
  
  <p>here is a small section of my CSV file:</p>
  
  <pre><code>1908,Souths,Easts,Souths,Cumberland,Y,14,12,4000
  1909,Souths,Balmain,Souths,Wests,N
  1910,Newtown,Souths,Newtown,Wests,Y,4,4,14000
  1911,Easts,Glebe,Glebe,Balmain,Y,11,8,20000
  1912,Easts,Glebe,Easts,Wests,N
  1913,Easts,Newtown,Easts,Wests,N
  </code></pre>
  
  <p>and here is my code so far</p>
  
  <pre><code>    import java.io.*;
  import java.util.*;
  
  public class ass2 {
  
      public static void main(String[] args) throws IOException {
          readData();
  
      }
  
      public static void readData() throws IOException{
          BufferedReader dataBR = new BufferedReader(new FileReader(new File("nrldata.txt")));
          String line = "";
  
          ArrayList&lt;String[]&gt; dataArr = new ArrayList&lt;String[]&gt;(); //An ArrayList is used because I don't know how many records are in the file.
  
          while ((line = dataBR.readLine()) != null) { // Read a single line from the file until there are no more lines to read
  
              String[] club = new String[9]; // Each club has 3 fields, so we need room for the 3 tokens.
  
              for (int i = 0; i &lt; 9; i++) { // For each token in the line that we've read:
                  String[] value = line.split(",", 9);                
                  club[i] = value[i]; // Place the token into the 'i'th "column"
              }
  
              dataArr.add(club); // Add the "club" info to the list of clubs.
          }
  
          for (int i = 0; i &lt; dataArr.size(); i++) {
              for (int x = 0; x &lt; dataArr.get(i).length; x++) {
                  System.out.printf("dataArr[%d][%d]: ", i, x);
                  System.out.println(dataArr.get(i)[x]);
              }
          }
      }
  </code></pre>
  
  <p>The error I get is:</p>
  
  <pre><code>Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 6
  at ass2.readData(ass2.java:23)
  at ass2.main(ass2.java:7)
  </code></pre>
  
  <p>Can someone please help :'(</p>
  
  <p>Thank you!</p>