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

[[水星, 金星, 地球, 火星, 冥王星], 
[土星, 天王星, 海王星, 冥王星, 木星]]
相关推荐
似水明俊德几秒前
01-C#.Net-泛型-学习笔记
java·笔记·学习·c#·.net
百锦再几秒前
飞算 JavaAI:我的编程强力助推引擎
java·spring·ai·编程·idea·code·飞算
wuyaolong00733 分钟前
Spring Boot 3.4 正式发布,结构化日志!
java·spring boot·后端
hua8722240 分钟前
Golang 构建学习
java·开发语言·学习
Halo_tjn1 小时前
Java 三个修饰符 相关知识点
java·开发语言
毕设源码-朱学姐1 小时前
【开题答辩全过程】以 广东省非遗文化信息管理系统的设计与实现为例,包含答辩的问题和答案
java
番茄去哪了1 小时前
Java基础面试题day01
java·开发语言·后端·javase·八股·面向对象编程
遇事不决问清风1 小时前
AI 驱动开发实战复盘:从 0 到上线,一个真实项目的工程化总结
java·ai编程
wuqingshun3141591 小时前
说说进程和线程的区别?
java·开发语言·jvm
Memory_荒年2 小时前
自定义 Spring Boot Starter:手搓“轮子”,但要搓出兰博基尼!
java·后端