Java List Sub List split(List from, int subListSize)

Here you can find the source of split(List from, int subListSize)

Description

Partition from into subLists, each of size subListSize.

License

Apache License

Declaration

public static <T> List<List<T>> split(List<T> from, int subListSize) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**// w  w  w .  j  a va 2  s  . com
     * Partition from into subLists, each of size subListSize.
     */
    public static <T> List<List<T>> split(List<T> from, int subListSize) {
        List<List<T>> into = new ArrayList<List<T>>();
        for (int first = 0; first < from.size(); first += subListSize) {
            into.add(from.subList(first, Math.min(first + subListSize, from.size())));
        }
        return into;
    }
}

Related

  1. getSubListFromStart(List list, int length)
  2. getSubListIndex(Object[] tofind, Object[] tokens)
  3. isSubList(List l1, List l)
  4. lastIndexOfSubList(final List list0, final List list1)
  5. slice(List stringList, int subListSize)
  6. splitIntoSubListsByNumber(final List list, final int numberOfSublists)
  7. splitList(List list, int subListNumber)
  8. splitListToSubLists(List parentList, int subListSize)
  9. startsWith(final List list, final List subList)