title: How can I fill two-dimensional arrayList with one dimensional?
body: <p>I have a problem that, whenever I try to fill two dimensional arrayList  (5x5) with one dimensional, I get index out of bounds exceptions. I guess that's because the square Array doesn't have index 0 value yet, but I don't know how to fix it.</p>
  <pre><code>ArrayList&lt;Character&gt; c = new ArrayList&lt;&gt;();
          
  // Copy character by character into arraylist 
  for (int i = 0; i &lt; finalArray.length(); i++) { 
      c.add(i, finalArray.charAt(i));
  } 
  
  ArrayList&lt;ArrayList&lt;Character&gt;&gt; square = new ArrayList&lt;&gt;();
  //square.add(new ArrayList&lt;&gt;()); 
  
  int k = 0;
  for(int i = 0; i &lt; 4; i++){
      for(int j = 0; j &lt; 4; j++){
          square.get(j).add(i, c.get(k));
          k++;
      }
  }
  </code></pre>