title: Printing 2D Arraylist
body: <p>When I try to print 2D <code>ArrayList</code>, the output looks like this:</p>
  
  <pre><code>A B CD E FG H I
  </code></pre>
  
  <p>instead of:</p>
  
  <pre><code>A B C
  D E F
  G H I
  </code></pre>
  
  <p>In the constructor  <code>public DenseBoard(T[][] x, T fillElem)</code>, I copy the elements of the 2D <code>array</code> into the 2D <code>ArrayList</code>. Then, in <code>toString()</code> method, I loop throught the elements of the 2D <code>ArrayList</code> and output the result (but I can't get the desired result as I've mentioned above)</p>
  
  <p>Class <strong>Tester</strong></p>
  
  <pre><code>public class Tester {
  
      public static void main(String[] args){
  
          String[][] myString = {{"A B C"}, {"D E F"}, {"G H I"}};
          DenseBoard&lt;String&gt; temp1 = new DenseBoard&lt;String&gt;(myString, "a");
          System.out.println(temp1);
      }
  }
  </code></pre>
  
  <p>Class <strong>DenseBoard</strong></p>
  
  <pre><code>import java.util.*;
  public class DenseBoard &lt;T&gt; {
  
      private T element;
      private ArrayList&lt;ArrayList&lt;T&gt;&gt; myBoard;
  
      public DenseBoard(T[][] x, T fillElem){
          this.myBoard = new ArrayList&lt;ArrayList&lt;T&gt;&gt;();
          this.element = fillElem;
  
          for(int i = 0; i &lt; x.length; i++){
              ArrayList&lt;T&gt; values = new ArrayList&lt;T&gt;();
              for(int j = 0; j &lt; x[i].length; j++){
                  values.add(x[i][j]);
              }
              myBoard.add(values);
          }
      }
  
      public String toString(){
          String result = "";
          for(int i = 0; i &lt; myBoard.size(); i++){
              for(int j = 0; j &lt; myBoard.get(i).size(); j++){
                  result += myBoard.get(i).get(j);
              }
              System.out.println();
          }
          return result;
      }
  }
  </code></pre>