title: Outputting integers from an ArrayList<ArrayList<Integer>> in Java
body: <p>I made an ArrayList&lt; ArrayList&lt; Integer >> to hold the coordinates of a chessboard.  I am having trouble simply outputting the numbers. When I output the sizes of the ArrayLists, it tells me safeSquares has 64 objects after the first set of for loops, but that innerList always has the size of zero after the "for(ArrayList innerList : safeSquares)" line.  It seems as though safeSquares never passes the arrayLists to innerList, but tries to 64 times.</p>
  
  <pre><code>static ArrayList&lt;ArrayList&lt;Integer&gt;&gt; safeSquares = new ArrayList&lt;ArrayList&lt;Integer&gt;&gt;();
  static ArrayList&lt;Integer&gt; squares = new ArrayList&lt;Integer&gt;();
  
  for(int i = 0; i &lt; 8; i++){
    squares.add(i);
    for(int x = 0; x &lt; 8; x++){
      squares.add(x);
      safeSquares.add(squares);
      squares.remove(1);
    }
    squares.clear();
  }
  
  for(ArrayList&lt;Integer&gt; innerList : safeSquares) {
    for (Integer number : innerList) {
      System.out.println(number + " ");
    }
  }
  </code></pre>