I have a usecase of picking up x number of elements in a batch from total n number of elements. Currently I'm using Google Guava Lists like this :
List<String> dataList;
List< List<String> > smallerLists = Lists.partition(dataList, maxRecordsInABatch);
for ( smallerList : smallerLists ) {
doSomething(data);
}
Is there a better way to do it, in which I can avoid making smallerLists and on-the run time pick x-sized lists from n-sized list.
I was also exploring Java 8 Streams and Lambda expressions but couldn't find something to cater this.
>`, i.e. neither source nor target ought to be a stream, `Lists.partition` is good enough (note the second answer there)…
– Holger Nov 22 '16 at 14:10