title: 2D ArrayList to a normal array java
body: <p>Basically, I am creating a dynamic 2d ArrayList.</p>
  
  <pre><code>private ArrayList&lt;char[]&gt; myArray;
  </code></pre>
  
  <p>This code below is done in loop. A few random strings of the "same length" is given to store
  the all the characters in array.</p>
  
  <p>while (body)</p>
  
  <pre><code>char[] temp = myString.toCharArray();
  myArray.add(temp);
  </code></pre>
  
  <p>So after all the characters are inserted into the ArrayList, I want to convert myArray into a normal array. (why? because it is going to be useful in future) And I think I am doing it wrong here:</p>
  
  <pre><code>charArray = (char[][]) myArray.toArray();
  //declaration of 'charArray' is already done at the start of the class.
  </code></pre>
  
  <p>So the problem is when I try to print the whole 'charArray' just to check, or any elements, I get an "java.lang.NullPointerException" error.</p>
  
  <p>So how do I covert the 2d ArrayList into a normal array ? I tried many different sources but didn't help.</p>
  
  <p>Thank you.</p>