My exact scenario is inserting data to database in batches, so I want to accumulate DOM objects then every 1000, flush them.
I implemented it by putting code in the
If you have guava dependency on your project you could do this:
StreamSupport.stream(Iterables.partition(simpleList, 1000).spliterator(), false).forEach(...);
See https://google.github.io/guava/releases/23.0/api/docs/com/google/common/collect/Lists.html#partition-java.util.List-int-