Java List Partition partition(List orig, int size)

Here you can find the source of partition(List orig, int size)

Description

partition

License

Open Source License

Declaration

public static <T> List<List<T>> partition(List<T> orig, 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 {
    public static <T> List<List<T>> partition(List<T> orig, int size) {
        if (orig == null) {
            throw new NullPointerException("The list to partition must not be null");
        }/*from ww w  .  j  ava2 s  .c o m*/
        if (size < 1) {
            throw new IllegalArgumentException("The target partition size must be 1 or greater");
        }
        int origSize = orig.size();
        List<List<T>> result = new ArrayList<>(origSize / size + 1);
        for (int i = 0; i < origSize; i += size) {
            result.add(orig.subList(i, Math.min(i + size, origSize)));
        }
        return result;
    }
}

Related

  1. partition(List list, int partitionSize)
  2. partition(List list, int size)
  3. partition(List list, int size)
  4. partition(List list, int size)
  5. partition(List longList, int length)
  6. partition(List sourceList, int numberOfSegments)
  7. partitionIntoFolds( List values, int numFolds)
  8. partitionList(final List originalList, final int chunkSize)
  9. partitionList(List list, int folds)