1.Google Guava
com.google.guava
guava
31.0.1-jre
List tempList = Arrays.asList("水星","金星","地球","火星",
"冥王星","土星","天王星","海王星","冥王星","木星");
// size 是把集合拆分的大小,size 为表示拆分成拆分的集合大小为3,
// 后面不足3的有多少算多少
List> partition = Lists.partition(tempList, 3);
System.out.println(partition);
[[水星, 金星, 地球],
[火星, 冥王星, 土星],
[天王星, 海王星, 冥王星],
[木星]]
2.apache commons
org.apache.commons
commons-collections4
4.4
List tempList = Arrays.asList("水星","金星","地球","火星","冥王星","土星","天王星","海王星","冥王星","木星");
List> partition = ListUtils.partition(tempList, 6);
System.out.println(partition);
[[水星, 金星, 地球, 火星, 冥王星, 土星],
[天王星, 海王星, 冥王星, 木星]]
3.Hutool
cn.hutool
hutool-all
5.7.14
List tempList = Arrays.asList("水星","金星","地球","火星","冥王星","土星","天王星","海王星","冥王星","木星");
List> partition = ListUtil.partition(tempList, 5);
System.out.println(partition);
[[水星, 金星, 地球, 火星, 冥王星],
[土星, 天王星, 海王星, 冥王星, 木星]]