collections - Is there a common Java utility to break a list into batches? - Stack Overflow
Check out Lists.partition(java.util.List, int)
from Google Guava:
Returns consecutive sublists of a list, each of the same size (the final list may be smaller). For example, partitioning a list containing
[a, b, c, d, e]
with a partition size of 3 yields[[a, b, c]
,[d, e]]
-- an outer list containing two inner lists of three and two elements, all in the original order.
Read full article from collections - Is there a common Java utility to break a list into batches? - Stack Overflow
No comments:
Post a Comment