title: Data from a txt file and into 2d array but shows arrayindexoutofbound error
body: <p>When I run this:</p>
  
  <pre><code>readData("data.txt")
  </code></pre>
  
  <p>I want to use this data for binary classification using SVM. Each data has a class label in the last column, so I put these in another array named <code>type</code>, but when I run, it prints all the value, but it then shows </p>
  
  <pre><code>Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
      at practice.A.readData(A.java:48)
      at practice.A.main(A.java:86)
  </code></pre>
  
  <p>i want to know what cause these exception</p>
  
  <pre><code>public class A {
      static double [][] train,testdata,attributes;
      static int row,col,x;;
      static double [] type;
      static void readData(String fileName)  {
      BufferedReader reader = null;
      try {
          reader = new BufferedReader(new FileReader(fileName));
          String line;
          line = reader.readLine();
          for(row=1;reader.readLine()!= null;row++) {}    
          col= 1;
          for (int i=0;i&lt;line.length();i++) {
              if(line.charAt(i)==',') 
                  col++;
          }
          System.out.println(row);
          System.out.println(col);
           x=col-1;
          if(reader!=null) reader.close();
          attributes = new double[row][x];
          reader = new BufferedReader(new FileReader(fileName));
          String []words=new String[col];
          type =new double[row];
          for(int i=0; i&lt;row;i++) {
              List&lt;String&gt; ob;
              ArrayList&lt;String&gt; w=new ArrayList&lt;&gt;();
              line = reader.readLine();
              words =line.split(",");
              if(!words[x].isEmpty())
                  type[i]=Double.parseDouble(words[x]);
              ob=Arrays.asList(words);
              w.addAll(ob);
              System.out.println(Arrays.toString(words));
              w.remove(x);
              String [] new_words=new String[w.size()];
              new_words=w.toArray(new_words);
              for(int j=0;j&lt;new_words.length;j++) {
                  if(!new_words[j].isEmpty()){
                      attributes[i][j] = Double.parseDouble(new_words[j]);
                      System.out.print(attributes[i][j]+" ");
                  }
              }
              w.clear();;
              System.out.println(type[i]);
          }
      } 
      catch (IOException e) {
          e.printStackTrace();
      }           
  }
  </code></pre>