Here you can find the source of partition(List
Parameter | Description |
---|---|
list | a parameter |
partitionSize | a parameter |
T | a parameter |
public static <T> List<List<T>> partition(List<T> list, int partitionSize)
//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; } }