Iterables.partition
很多时候都有将List拆分为给定大小的多个子列表的操作,以前需要写很多复杂的逻辑才能实现,试试
强大的集合工具Iterables
Guava
提供了一些java.util.Collections
中没有提供的关于Iterable的公共操作,
而这些操作都封装在了工具类 - Iterables
中.
List<Integer> list1 = Lists.newArrayListWithCapacity(0); list1.add(null); list1.add(1); list1.add(2); list1.add(9); List<Integer> list2 = Lists.newArrayListWithCapacity(0); list2.add(2); list2.add(3); list2.add(4); list2.add(6);
合并方法 - concat()
Iterable<Integer> testIterable = Iterables.concat(list1, list2);
System.out.println(testIterable);//[null, 1, 2, 9, 2, 3, 4, 6]
分区方法 - partition()
Iterables
提供了对指定Iterable<T>
通过指定分区大小进行分区.并返回Iterable<List<T>>
.
需要注意的是:Iterable
不能为NULL
并且指定的分区大小必须大于0.
Iterable<List<Integer>> partition = Iterables.partition(testIterable, 3); System.out.println(partition);//[[null, 1, 2], [9, 2, 3], [4, 6]]
---------------------------------------------------------------------------
国之殇,未敢忘!
南京大屠杀!
731部队!
以及核污染水排海等一系列全无人性的操作,购买他们的食品和为它们提供帮助只会更加变本加厉的害你,呼吁大家不要购买日本相关产品
昭昭前事,惕惕后人
吾辈当自强,方使国不受他人之侮!
---------------------------------------------------------------------------
作者:三号小玩家
出处:https://www.cnblogs.com/q1359720840/
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。 版权信息