Java 8 Stream with batch processing

前端 未结 15 885
醉梦人生
醉梦人生 2020-11-28 02:42

I have a large file that contains a list of items.

I would like to create a batch of items, make an HTTP request with this batch (all of the items are needed as par

15条回答
  •  旧巷少年郎
    2020-11-28 03:30

    For completeness, here is a Guava solution.

    Iterators.partition(stream.iterator(), batchSize).forEachRemaining(this::process);
    

    In the question the collection is available so a stream isn't needed and it can be written as,

    Iterables.partition(data, batchSize).forEach(this::process);
    

提交回复
热议问题