I want to be able to collect a list of elements of fixed size of 50 elements. Here is how I am currently doing it. I would like to use lambdas if possible.
List<Contact> contactList=getContacts();
Iterator<Contact> it=contactList.iterator();
List<Contact> batch=new ArrayList<>();
while(it.hasNext()) {
if(batch.size()<50) {
batch.add(it.next())
} else {
processBatch(batch);
}
//When iterator has less than 50 elements
if (!it.hasNext() && batch.size()<50) {
processBatch(batch);
}
}