List 分批处理

1.Google Guava

java 复制代码
<dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>31.0.1-jre</version>
 </dependency>

List<String> tempList = Arrays.asList("水星","金星","地球","火星",
"冥王星","土星","天王星","海王星","冥王星","木星");
// size 是把集合拆分的大小,size 为表示拆分成拆分的集合大小为3,
// 后面不足3的有多少算多少
List<List<String>> partition = Lists.partition(tempList, 3);
System.out.println(partition);

[[水星, 金星, 地球], 
[火星, 冥王星, 土星], 
[天王星, 海王星, 冥王星], 
[木星]]

2.apache commons

java 复制代码
<dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-collections4</artifactId>
            <version>4.4</version>
        </dependency>

List<String> tempList = Arrays.asList("水星","金星","地球","火星","冥王星","土星","天王星","海王星","冥王星","木星");
List<List<String>> partition = ListUtils.partition(tempList, 6);
 
System.out.println(partition);

[[水星, 金星, 地球, 火星, 冥王星, 土星],
 [天王星, 海王星, 冥王星, 木星]]

3.Hutool

java 复制代码
<dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
            <version>5.7.14</version>
        </dependency>
List<String> tempList = Arrays.asList("水星","金星","地球","火星","冥王星","土星","天王星","海王星","冥王星","木星");
 List<List<String>> partition = ListUtil.partition(tempList, 5);
 
 System.out.println(partition);

[[水星, 金星, 地球, 火星, 冥王星], 
[土星, 天王星, 海王星, 冥王星, 木星]]
相关推荐
有梦想的骇客4 小时前
书籍“之“字形打印矩阵(8)0609
java·算法·矩阵
yours_Gabriel4 小时前
【java面试】微服务篇
java·微服务·中间件·面试·kafka·rabbitmq
BillKu5 小时前
MyBatis中foreach集合用法详解
windows·mybatis
hashiqimiya6 小时前
android studio中修改java逻辑对应配置的xml文件
xml·java·android studio
扛枪的书生6 小时前
AD 横向移动-LSASS 进程转储
windows·渗透·kali·域渗透
liuzhenghua666 小时前
Python任务调度模型
java·运维·python
結城7 小时前
mybatisX的使用,简化springboot的开发,不用再写entity、mapper以及service了!
java·spring boot·后端
地衣君7 小时前
PowerShell 美化——oh-my-posh 的配置与使用
windows
小前端大牛马7 小时前
java教程笔记(十一)-泛型
java·笔记·python
东阳马生架构7 小时前
商品中心—2.商品生命周期和状态的技术文档
java