title: Java: Storing values in 2D Array
body: <p>I have a problem with storing values in a multidimensional array. The main concept of the idea is that I have an arraylist which is called user_decide and I transform it in a array. So, the decide array looks like [1, 45, 656, 8, 97, 897], but all the rows don't have the same number of elements. Then, I split this replace [,] and spaces and I would like to store each value individually in a 2D array. So, I split it with the "," and try to store each value in a different position. Everything seems to be printed great, even the cut[j] is what I want to store, but I get a java.lang.NullPointerException, which I don't get. The count variable is actually the count = user_decide.size()</p>
  
  <pre><code>String [] decide = user_decide.toArray(new String[user_decide.size()]);
  for (int i = 0; i &lt; count; i ++){
     decide[i] =
        decide[i].replaceAll("\\s", "").replaceAll("\\[","").replaceAll("\\]", "");
  }
  String [][] data1 = new String[count][];
  for (int i = 0; i &lt; count; i++){
     String [] cut = decide[i].split("\\,");
     for (int j = 0; j &lt; cut.length; j++){
        System.out.println(cut[j]);
        data1[i][j] = cut[j];
     }
  }
  </code></pre>
  
  <p>Another question is why I cannot store it in a Int [][] array? Is there a way to do that?</p>
  
  <p>Thank you a lot.</p>
  
  <p>** EDIT **</p>
  
  <p>I just made an edit about my answer after I accepted the question. I am trying to store it in a 2D int array. </p>
  
  <pre><code>String [][] data1 = new String[user_decide.size()][];
  int [][] data = new int [user_decide.size()][];
  
  for (int i = 0; i &lt; user_decide.size(); i++){
      data1[i] = decide[i].split("\\,");
      for (int j = 0; j &lt; data1[i].length; j++) {
          data[i] = new int [data1[i].length]; 
          data[i][j] = Integer.parseInt(data1[i][j]);
          System.out.println(data1[i][j]);
      }
  }
  </code></pre>