Java List Partition partition(List list, int partitionSize)

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

Description

Partitions a list into multiple smaller lists from a partition size.

License

Open Source License

Parameter

Parameter Description
list a parameter
partitionSize a parameter
T a parameter

Declaration

public static <T> List<List<T>> partition(List<T> list, 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 w  w w.  j av  a 2 s .c  o  m
     * Partitions a list into multiple smaller lists from a partition size.
     * @param list
     * @param partitionSize
     * @param <T>
     * @return
     */
    public static <T> List<List<T>> partition(List<T> list, int partitionSize) {
        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;
    }
}

Related

  1. partition(List list, Integer batchSize)
  2. partition(List all, int partitionSize)
  3. partition(List a, int lower, int upper)
  4. partition(List items, int slices)
  5. partition(List list, int num)
  6. partition(List list, int size)
  7. partition(List list, int size)
  8. partition(List list, int size)
  9. partition(List longList, int length)