Back
How can I split an ArrayList (size=1000) in multiple ArrayLists of the same size (=10) ?
ArrayList<Integer> results;
Apache Commons Collections 4 has a partition method in the ListUtils class. Here’s how it works:
import org.apache.commons.collections4.ListUtils;...int targetSize = 100;List<Integer> largeList = ...List<List<Integer>> output = ListUtils.partition(largeList, targetSize);
import org.apache.commons.collections4.ListUtils;
...
int targetSize = 100;
List<Integer> largeList = ...
List<List<Integer>> output = ListUtils.partition(largeList, targetSize);
31k questions
32.8k answers
501 comments
693 users