Java List Split split(final List orginalList, final int splitSize)

Here you can find the source of split(final List orginalList, final int splitSize)

Description

split

License

Apache License

Declaration

public static <T> List<List<T>> split(final List<T> orginalList, final int splitSize) 

Method Source Code


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

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

public class Main {
    public static <T> List<List<T>> split(final List<T> orginalList, final int splitSize) {
        int startIndex = 0;
        int endIndex = splitSize;
        List<List<T>> lists = new ArrayList<List<T>>();
        for (int i = 1;;) {
            if (endIndex <= orginalList.size()) {
                lists.add(orginalList.subList(startIndex, endIndex));
                startIndex = endIndex;// ww  w  . j  av  a2  s  .c  o m
                ++i;
                endIndex = i * splitSize;
            } else if (startIndex < orginalList.size()) {
                lists.add(orginalList.subList(startIndex, orginalList.size()));
                break;
            } else
                break;

        }
        return lists;
    }
}

Related

  1. split(final List list, final int count)
  2. split(final List list, final int index)
  3. split(final List original, final int maxListSize, final Class listImplementation)
  4. split(final String line, final char delimiter, final List parts)
  5. split(List data, int max)
  6. split(List list)