Java List Split split(List list, int size)

Here you can find the source of split(List list, int size)

Description

Splits a List into a list of smaller lists within the maximum size.

License

Open Source License

Declaration

public static final <T extends Object> List<List<T>> split(List<T> list, int size) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;
import java.util.List;

public class Main {
    /**// w ww .j  a  v a  2s .  c om
     * Splits a List into a list of smaller lists within the maximum size.
     */
    public static final <T extends Object> List<List<T>> split(List<T> list, int size) {
        if (size == 0) {
            throw new IllegalArgumentException("List size must be > 0");
        }
        List<List<T>> lists = new ArrayList<List<T>>();
        for (int i = 0; i < list.size(); i += size) {
            lists.add(list.subList(i, Math.min(i + size, list.size())));
        }
        return lists;
    }
}

Related

  1. split(List list)
  2. split(List list, final int parts)
  3. split(List list, int size)
  4. split(List list, int size)
  5. split(List list, int size)
  6. split(List list, int splitSize)
  7. split(List lst)
  8. split(List toSplit, int howOften)
  9. split(List list, int divide)