Contents

How to Split or Partition a List into Batches in Java

Updated on 2026-10-21

Introduction

In this blog post, we will explore a simple and efficient way to split a List into smaller chunks using Java without needing any third-party libraries. This approach can be handy for dealing with large data sets and optimizing performance. Whether it's for efficient processing or easier data manipulation, splitting a list can be a valuable tool.

How to chunk a list in Java

In the following example, a list of fruits is split into two groups using Java Streams and Collectors.groupingBy.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
List<String> fruits = new ArrayList<>();
fruits.add("Apple");
fruits.add("pear");
fruits.add("Banana");
fruits.add("Orange");

AtomicInteger counter = new AtomicInteger();
int groupSize = 2;
Map<Integer, List<String>> listOfChunks = fruits.stream()
.collect(Collectors.groupingBy(it -> counter.getAndIncrement() / groupSize));

Return a List of lists containing chunks

The following example is almost the same as the previous one except for line 13. On line 13, we use the ArrayList constructor to create a list that contains the lists of chunks.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
List<String> fruits = new ArrayList<>();
fruits.add("Apple");
fruits.add("pear");
fruits.add("Banana");
fruits.add("Orange");

AtomicInteger counter = new AtomicInteger();
int groupSize = 2;
Map<Integer, List<String>> mapOfChunks = fruits.stream()
.collect(Collectors.groupingBy(it -> counter.getAndIncrement() / groupSize));
// Create a list containing the lists of chunks
List<List<String>> ListOfChunks = new ArrayList<>(mapOfChunks.values());

Conclusion

While several third-party libraries and frameworks are available to accomplish this, it's possible to do it without relying on external dependencies. In this blog post, we have explored a simple approach to splitting a list using Java, which is easily adapted to different use cases.

⚡ Enterprise Java Training · 1 Day (Live In-Person On-Site)

Bring Hands-On Modern Java Training to Your Engineering Team

Want to level up your team on Java Virtual Threads & Concurrency, Project Panama (FFM API) & High-Performance I/O, or Modern Testing in Java? I deliver intensive 1-day workshops customized to your company's tech stack and production challenges.

Stay Connected · Code, Benchmarks & Talks

Want More Deep-Dive JVM Benchmarks & Project Panama Research?

Follow my weekly engineering posts on LinkedIn, explore the full JMH benchmark suites and pure-Java Linux io_uring / FUSE projects on GitHub, or download my conference talk slides:

David Vlijmincx
David Vlijmincx

Senior Java Performance & Concurrency Engineer with 10+ years of production JVM experience. International speaker with 35+ talks at Devoxx, P99 CONF, JFokus, JavaZone, and Devnexus, creator of JUring (Linux io_uring for Java), and enterprise Java workshop trainer.