Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (10.2k points)

How can I split an ArrayList (size=1000) in multiple ArrayLists of the same size (=10) ?

ArrayList<Integer> results;

1 Answer

0 votes
by (46k points)

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);

Related questions

0 votes
1 answer
asked Nov 20, 2019 in Java by Nigam (4k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...