Here you can find the source of splitListByPartitionSize(List> list, int partitionSize)
Parameter | Description |
---|---|
list | wanted to split |
partitionSize | size of every partition created from the list |
public static List<List<?>> splitListByPartitionSize(List<?> 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 a v a 2 s. co m*/ * to split a list into lists with equally sized * @param list wanted to split * @param partitionSize size of every partition created from the list * @return a List which holds ArrayLists with size of the given partitionSize */ public static List<List<?>> splitListByPartitionSize(List<?> list, int partitionSize) { List<List<?>> partitionList = new ArrayList<>(); for (int i = 0; i < list.size(); i += partitionSize) { List subList = new ArrayList(list.subList(i, Math.min(i + partitionSize, list.size()))); partitionList.add(subList); } return partitionList; } }