更新时间:2023-01-11 15:36:48
可以使用拆分列表功能.
You can use split list function.
private static List<List<Integer>> splitAndReturn(List<Integer> numbers,
int size) {
List<List<Integer>> smallList = new ArrayList<List<Integer>>();
int i = 0;
while (i + size < numbers.size()) {
smallList.add(numbers.subList(i, i + size));
i = i + size;
}
smallList.add(numbers.subList(i, numbers.size()));
return smallList;
}
该函数将返回一个数组的arrayList,每个原始大小为size
.因此,如果您需要 100 个大小为 10 的数组,则
The function will return an arrayList of arrays with each raw of size size
.
So if you need 100 array with size 10, then
splitAndReturn(yourList, 10).subList(0, 100);
会给你数组列表.