guava java扩展类库, 提供了一些api方便操作
Lists.partition(List list,int size)
将list 集合 进行切割 然后填充到 一个List集合里。
例如:
List<Integer> numList = Lists.newArrayList(1, 2, 3, 4, 5, 6, 7, 8);
List<List<Integer>> lists=Lists.partition(numList,3);
System.out.println(lists);//[[1, 2, 3], [4, 5, 6], [7, 8]]
网友评论