Java List Partition partitionList(List list, final int partitionSize)

Here you can find the source of partitionList(List list, final int partitionSize)

Description

Partition a list into sublists of length L.

License

Open Source License

Declaration

private static <T> List<List<T>> partitionList(List<T> list, final int partitionSize) 

Method Source Code


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

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**/*from www . ja  v  a2 s .co m*/
     * Partition a list into sublists of length L. The last list may have a size smaller than L.<br>
     * The sublists are backed by the original list.
     */
    private static <T> List<List<T>> partitionList(List<T> list, final int partitionSize) {
        assert partitionSize > 0;
        assert list != null;
        final List<List<T>> res = new ArrayList<>();
        for (int i = 0; i < list.size(); i += partitionSize) {
            res.add(list.subList(i, Math.min(list.size(), i + partitionSize)));
        }
        return res;
    }
}

Related

  1. partition(List orig, int size)
  2. partition(List sourceList, int numberOfSegments)
  3. partitionIntoFolds( List values, int numFolds)
  4. partitionList(final List originalList, final int chunkSize)
  5. partitionList(List list, int folds)
  6. partitionVariable(List arr, int chunk)
  7. removePartition(List donorPartitionList, int partition)
  8. splitListByPartitionSize(List list, int partitionSize)