JAVA – How to Split an ArrayList in Multiple Small ArrayLists

By | July 29, 2018

This is a sample how to split an arraylist in multiple small arraylists in java code.

How to Split an ArrayList in Java

List<List<String>> batchData = new ArrayList<>();
int size = 1000;
for (int start = 0; start < data.size(); start += size) {
  int end = Math.min(start + size, data.size());
  List<String> sublist = data.subList(start, end);
  batchData.add(sublist);
}

Sublist is a function to split your arraylist data into multiple arraylists.

How to Split an ArrayList in Java

For other example you can search in google with this keyword : “How to Split an ArrayList in Java”.

Leave a Reply

Your email address will not be published. Required fields are marked *