Here you can find the source of partitionList(final List
private static <T> List<List<T>> partitionList(final List<T> originalList, final int chunkSize)
//package com.java2s; // Licensed to the Apache Software Foundation (ASF) under one import java.util.ArrayList; import java.util.List; public class Main { private static <T> List<List<T>> partitionList(final List<T> originalList, final int chunkSize) { final List<List<T>> listOfChunks = new ArrayList<List<T>>(); for (int i = 0; i < originalList.size() / chunkSize; i++) { listOfChunks.add(originalList.subList(i * chunkSize, i * chunkSize + chunkSize)); }// www . j a v a2 s. co m if (originalList.size() % chunkSize != 0) { listOfChunks.add(originalList.subList(originalList.size() - originalList.size() % chunkSize, originalList.size())); } return listOfChunks; } }