title: Is there a common Java utility to break a list into batches?
body: <p>I wrote myself a utility to break a list into batches of given size. I just wanted to know if there is already any apache commons util for this.</p>
  
  <pre><code>public static &lt;T&gt; List&lt;List&lt;T&gt;&gt; getBatches(List&lt;T&gt; collection,int batchSize){
      int i = 0;
      List&lt;List&lt;T&gt;&gt; batches = new ArrayList&lt;List&lt;T&gt;&gt;();
      while(i&lt;collection.size()){
          int nextInc = Math.min(collection.size()-i,batchSize);
          List&lt;T&gt; batch = collection.subList(i,i+nextInc);
          batches.add(batch);
          i = i + nextInc;
      }
  
      return batches;
  }
  </code></pre>
  
  <p>Please let me know if there any existing utility already for the same.</p>