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

[[水星, 金星, 地球, 火星, 冥王星], 
[土星, 天王星, 海王星, 冥王星, 木星]]
相关推荐
NE_STOP6 小时前
Vide Coding--AI编程工具的选择
java
码云数智-园园6 小时前
C++20 Modules 模块详解
java·开发语言·spring
程序员黑豆6 小时前
JDK 下载安装与配置详细教程
java·前端·ai编程
小宇宙Zz7 小时前
Maven依赖冲突
java·服务器·maven
swordbob7 小时前
NIO的channel中什么是 fd(File Descriptor,文件描述符)
java·开发语言·nio
qq_369224337 小时前
Windows全系通用!ntdll.dll文件丢失、报错、闪退问题的完整排查与修复教程
windows·dll·dll修复·dll丢失·dll错误
咖啡八杯7 小时前
GoF设计模式——享元模式
java·spring·设计模式·享元模式
十五喵源码网7 小时前
基于springboot2+vue2的租房管理系统
java·毕业设计·springboot·论文笔记
摇滚侠7 小时前
IDEA 创建 Java 项目 手动整合 SSM 框架
java·ide·intellij-idea
源分享7 小时前
Java线程同步的多种实现方法(非常详细)
java·开发语言·jvm