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);

[[水星, 金星, 地球, 火星, 冥王星], 
[土星, 天王星, 海王星, 冥王星, 木星]]
相关推荐
ym hyd 1118 分钟前
题库建立与考试系统源码 Java+SpringBoot+Vue3 前后分离
java·开发语言·vue.js·spring boot·毕设
risc12345612 分钟前
什么是码点?
java
apple_6926588525 分钟前
Github开源免费 红果短剧 Windows 电脑桌面版:民间开发者做的第三方播放器,不用装模拟器了
windows
JavaPub-rodert37 分钟前
公共 Docker 镜像源总失效?用 Harbor Proxy Cache 自建 Docker Hub 镜像缓存
java·缓存·docker
智鸟科技GemeOpen开发者智能设备38 分钟前
平安校园 AI 智能实时告警系统 智鸟科技·GemeOpen + 谷华科技·融合创新方案白皮书
java·开发语言·python·物联网·智能家居
自强的小白1 小时前
nacos配置中心面试题(导入配置的优先级),注意是如果后导入相同配置是以 后导入优先。外部入优先和nacos的数据隔离。
java·微服务
Wang's Blog1 小时前
Java框架 SpringCloud 快速入门: Feign 的自定义配置与日志级别
java·开发语言·spring cloud
Vex2une1 小时前
Windows 系统还原发展史:从快照回滚到现代恢复生态
windows·系统还原·系统重置·卷影复制·系统保护·windows re·系统映像备份
Hello_Pyhx1 小时前
挖兔硬盘精灵 WatuDisk:从首次检测到日常检查的使用指南
运维·windows·硬盘·维护
成旭先生1 小时前
企业全景信息查询 API:工商照面 33 项、股东出资、变更与社保一次查全
java·开发语言·api接口·企业信息查询·工商数据·风控尽调·供应商准入