List根据长度分割

使用guave实现 ``` @Test public void test1() { List<List<Integer>> partitions = Lists.partition(lists, 10); for (List<Integer> list : partitions) { System.out.println(list); } } ``` pom.xml文件 ``` <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>27.1-jre</version> </dependency> ``` 纯代码实现 ``` public static <T> List<List<T>> splitList(List<T> list, int groupSize){ int length = list.size(); // 计算可以分成多少组 int num = ( length + groupSize - 1 )/groupSize ; // TODO List<List<T>> newList = new ArrayList<>(num); for (int i = 0; i < num; i++) { // 开始位置 int fromIndex = i * groupSize; // 结束位置 int toIndex = (i+1) * groupSize < length ? ( i+1 ) * groupSize : length ; newList.add(list.subList(fromIndex,toIndex)) ; } return newList ; } ```