title: Multi-dimensional array list java
body: <p>I'm trying to do an multi-dimensional <code>ArrayList</code>, so I've come up with the method of doing: </p>
  
  <pre><code>int NumberInColumns = (int) Math.floor(listAnswers.size() / NUMBER_OF_COLUMNS);
  // make higher number of answers on the right
  if (listAnswers.size() % NUMBER_OF_COLUMNS &gt; 0)
          NumberInColumns++;
  ArrayList&lt;HolderAnswer&gt; listAnswers = getAnswers();
  ArrayList&lt;ArrayList&lt;HolderAnswer&gt;&gt; listAnswersSorted = new ArrayList&lt;ArrayList&lt;HolderAnswer&gt;&gt;();
  
  int k=0;
  for (HolderAnswer answer : listAnswers) {
      ArrayList&lt;HolderAnswer&gt; temp = new ArrayList&lt;HolderAnswer&gt;();
      temp.add(answer);   
      if (k % NumberInColumns == 0 ) { 
              listAnswersSorted.add(temp);            
          }
          else { 
              if (k == listAnswers.size()) { 
                  listAnswersSorted.add(temp);
              }
          }
          k++;
  }
  </code></pre>
  
  <p>The problem I'm having is that with an <code>ArrayList.size()</code> of 7, I'm only getting the first and fifth records when I try and get the information out of the array.  What am I missing?</p>