title: How to split an arraylist into multiple arraylist of equal sizes?
body: <p>thank you in advance for your attention.
  I'll explain my situation, I need to separate an arraylist into multiple arraylist.
  For example, I need to make requests for an api, in which I can only pass 50 items. Sometimes I need to query more than 50 items, so I need to make 2 requests for api, each with 50 items. Another situation would be, an array with 120 items, I would then need to make 3 requests, in the first 2 I pass 50 items, and in the third and last I would spend the last 20, so I would like to split this main arraylist with 120 items in 3 arrayslist, 2 with size of 50, and the third with size of 20. Below is the code I am using to do this but I am not succeeding, I would like to know a better solution for this. Thank you!</p>
  
  <pre><code>private ArrayList&lt;String&gt; idsVideos = new ArrayList&lt;&gt;();
  private ArrayList&lt;String&gt; testeTrab = new ArrayList&lt;&gt;();
  private ArrayList&lt;ArrayList&lt;String&gt;&gt; videosArrays= new ArrayList&lt;&gt;();    
  
   for (int i =0; i &lt; idsVideos.size(); i++){
  
                          if (testeTrab.size() ==  50) {
                              videosArrays.add(testeTrab);
                              testeTrab.clear();
                          }
                          testeTrab.add(idsVideos.get(i));
                          idsVideos.remove(i);
                      }
  
  
                      if (testeTrab.size() &gt; 0  &amp;&amp; videosArrays.size() &gt; 0) {
                          videosArrays.add(testeTrab);       
                          testeTrab.clear();
  
                      }
  </code></pre>