title: How can I split an ArrayList into several lists?
body: <p>See the following ArrayList:</p>
  
  <pre><code>List&lt;Integer&gt; values = new ArrayList&lt;Integer&gt;();
  values.add(0);
  values.add(1);
  values.add(2);
  values.add(3);
  values.add(4);
  values.add(5);
  values.add(6);
  </code></pre>
  
  <p>So we have:</p>
  
  <pre><code>integerList.size(); // outputs 7 elements
  </code></pre>
  
  <p>I need to show a <a href="http://code.google.com/apis/chart/" rel="nofollow noreferrer">Google chart</a> as follows:</p>
  
  <blockquote>
    <p><a href="http://chart.apis.google.com/chart?chs=300x200&amp;chd=t:60,-1,80,60,70,35&amp;cht=bvg&amp;chbh=20,4,20&amp;chco=4C5F2B,BED730,323C19&amp;chxt=y&amp;chxr=0,0,500" rel="nofollow noreferrer">http://chart.apis.google.com/chart?chs=300x200&amp;chd=t:60,-1,80,60,70,35&amp;cht=bvg&amp;chbh=20,4,20&amp;chco=4C5F2B,BED730,323C19&amp;chxt=y&amp;chxr=0,0,500</a></p>
  </blockquote>
  
  <p>To generate its values, I just call</p>
  
  <pre><code>StringUtils.join(values, ","); // outputs 0,1,2,3,4,5,6
  </code></pre>
  
  <p>It happens <strong>it supports up to</strong> 1000 pixel width. So if I have many values, I need to split my ArrayList into other ArrayLists to generate other charts. Something like:</p>
  
  <pre><code>Integer targetSize = 3; // And suppose each target ArrayList has size equal to 3
  
  // ANSWER GOES HERE
  List&lt;List&lt;Integer&gt;&gt; output = SomeHelper.split(values, targetSize);
  </code></pre>
  
  <p>What Helper should I use to get my goal?</p>