class="java">public class ListGroupUtil {
    /**
     * 将原始list按照MAX_LIST_SIZE分组
     * @param list
     * @return
     */
    public static <E> List<List<E>> generateListGroup(List<E> list, int maxListSize) {
        List<List<E>> listGroup = Lists.newArrayList();
        if (CollectionUtils.isEmpty(list) || list.size() <= maxListSize) {
            listGroup.add(list);
        } else {
            int pages = (int) Math.ceil((double)list.size() / (double)maxListSize);
            for (int i = 0; i < pages; i++) {
                int fromIndex = i * maxListSize;
                int toIndex = (i + 1) * maxListSize > list.size() ? list.size()
                        : (i + 1) * maxListSize;
                List<E> subList = list.subList(fromIndex, toIndex);
                listGroup.add(subList);
            }
        }
        return listGroup;
    }
}
?