【发布时间】:2020-01-17 18:32:40
【问题描述】:
所以,我已经阅读了很多关于如何从多个数组列表创建 Arraylist 的内容,但并非相反。我发现一些代码可以查看基于单个数组列表的某些数组列表,但我不需要该视图。我需要从一个数组列表(长度为 81)创建新的数组列表列表(长度为 9)。 问题是我需要有可能单独管理每个数组列表。
static ArrayList<Integer> nums = new ArrayList<Integer>();
> Output :
[0, 0, 1, 0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4, 5, 0, 5, 6, 0,
> 6, 7, 0, 7, 8, 0, 8, 9, 1, 0, 2, 1, 1, 3, 1, 2, 4, 1, 3, 5, 1, 4, 6,
> 1, 5, 7, 1, 6, 8, 1, 7, 9, 1, 8, 1, 2, 0, 3, 2, 1, 4, 2, 2, 5, 2, 3,
> 6, 2, 4, 7, 2, 5, 8, 2, 6, 9, 2, 7, 1, 2, 8, 2, 3, 0, 4, 3, 1, 5, 3,
> 2, 6, 3, 3, 7, 3, 4, 8, 3, 5, 9, 3, 6, 1, 3, 7, 2, 3, 8, 3, 4, 0, 5,
> 4, 1, 6, 4, 2, 7, 4, 3, 8, 4, 4, 9, 4, 5, 1, 4, 6, 2, 4, 7, 3, 4, 8,
> 4, 5, 0, 6, 5, 1, 7, 5, 2, 8, 5, 3, 9, 5, 4, 1, 5, 5, 2, 5, 6, 3, 5,
> 7, 4, 5, 8, 5, 6, 0, 7, 6, 1, 8, 6, 2, 9, 6, 3, 1, 6, 4, 2, 6, 5, 3,
> 6, 6, 4, 6, 7, 5, 6, 8, 6, 7, 0, 8, 7, 1, 9, 7, 2, 1, 7, 3, 2, 7, 4,
> 3, 7, 5, 4, 7, 6, 5, 7, 7, 6, 7, 8, 7, 8, 0, 9, 8, 1, 1, 8, 2, 2, 8,
> 3, 3, 8, 4, 4, 8, 5, 5, 8, 6, 6, 8, 7, 7, 8, 8, 8]
我找到了这段代码:
List<Integer> bigList = nums
List<List<Integer>> smallerLists = Lists.partition(bigList, 10);
但由于某种原因它不起作用,因为我无法在 Guava 库中导入 lists.partition() 方法
【问题讨论】:
-
您是否考虑过使用循环而不是尝试查找库函数?