The following code chunks a List in functional style:
AtomicInteger counter = new AtomicInteger(); Collection result = list.stream() .collect(Collectors.groupingBy(c - counter.getAndIncrement() / chunkSize)) .values();