Java Utililty Methods List Partition

List of utility methods to do List Partition

Description

The list of methods to do List Partition are organized into topic(s).

Method

List>partition(final List items, final int size)
partition
if (items == null) {
    throw new IllegalArgumentException("Items must not be null");
if (size < 0) {
    throw new IllegalArgumentException("Size must be more than 0");
final int maxIndex = items.size() < size ? items.size() : size;
final List<List<T>> lists = new ArrayList<>();
...
List>partition(final List list, final int length)
Partitions a list of objects into smaller lists
final List<List<T>> parts = new ArrayList<>();
for (int i = 0; i < list.size(); i += length) {
    parts.add(new ArrayList<>(list.subList(i, Math.min(list.size(), i + length))));
return parts;
List>partition(List list, Integer batchSize)
Partition a list in sub-lists, with max size equal to 'batchSize' parameter.
List<List<E>> retObj = new ArrayList<List<E>>();
if (isNotEmpty(list)) {
    retObj = new ArrayList<List<E>>();
    List<E> currentList = null;
    for (int i = 0; i < list.size(); i++) {
        if (i % batchSize == 0) {
            currentList = new ArrayList<E>();
            retObj.add(currentList);
...
List>partition(List all, int partitionSize)
partition
List<List<Long>> partitions = new ArrayList<>();
final int count = all.size();
for (int i = 0; i < count; i += partitionSize) {
    partitions.add(new ArrayList<>(all.subList(i, Math.min(count, i + partitionSize))));
return partitions;
intpartition(List a, int lower, int upper)
Performs QuickSort partitioning: Rearranges an array in two partitions.
T x = a.get(upper);
int i = lower - 1;
for (int j = lower; j < upper; j++) {
    if (a.get(j).compareTo(x) <= 0) {
        i++;
        exchange(a, i, j);
exchange(a, i + 1, upper);
return i + 1;
List>partition(List items, int slices)
partition
double size = items.size() / (double) slices;
double accum = 0;
int start = 0;
List<List<T>> list = new ArrayList<>(slices);
for (int i = 0; i < slices; i++) {
    int end = (int) Math.floor(accum + size);
    if (i == slices - 1)
        end = items.size();
...
List>partition(List list, int num)
Partition a list into num sub-lists.
if (num < 1) {
    throw new IllegalArgumentException("Number of sub-lists must be greater than zero");
List<List<T>> result = new ArrayList<List<T>>();
int index = 0;
int listsRemaining = num;
int elementsRemaining = list.size();
while (elementsRemaining > 0) {
...
List>partition(List list, int partitionSize)
Partitions a list into multiple smaller lists from a partition size.
List<List<T>> partitions = new ArrayList<>();
final int algebraN = list.size();
for (int i = 0; i < algebraN; i += partitionSize) {
    partitions.add(new ArrayList<T>(list.subList(i, Math.min(algebraN, i + partitionSize))));
return partitions;
List>partition(List list, int size)
partition
if (size <= 0) {
    throw new IllegalArgumentException("bad size: " + size);
List<List<T>> lists = new ArrayList<>();
for (int i = 0; i < list.size(); i += size) {
    int fromIndex = i;
    int toIndex = fromIndex + size;
    toIndex = toIndex > list.size() ? list.size() : toIndex;
...
List>partition(List list, int size)
partition
if (size <= 0) {
    throw new IllegalArgumentException("Size should be >= 0");
if (list == null) {
    throw new IllegalArgumentException("List can't be null");
List<List<T>> partitions = new ArrayList<List<T>>(list.size() / size);
List<T> partition = new ArrayList<T>(size);
...