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

[[水星, 金星, 地球, 火星, 冥王星], 
[土星, 天王星, 海王星, 冥王星, 木星]]
相关推荐
心勤则明9 分钟前
JVM(Java虚拟机)运行时数据区
java·jvm·chrome
皮皮林55131 分钟前
多账号统一登录(实现方案)
java
越来越无动于衷1 小时前
智慧社区(八)——社区人脸识别出入管理系统设计与实现
java·开发语言·spring boot·python·mysql
Mr Aokey1 小时前
注解退散!纯XML打造MyBatis持久层的终极形态
xml·java·mybatis
向日葵花子(* ̄︶ ̄)1 小时前
Eclipse中导入新项目,右键项目没有Run on Server,Tomcat的add and remove找不到项目
java·eclipse
jie*2 小时前
小杰数据结构——题库——拂衣便欲沧海去,但许明月随吾身
数据结构·windows·python
超级小忍2 小时前
Maven 常用命令详解
java·开发语言·maven
小白的代码日记3 小时前
基于 Spring Boot 的小区人脸识别与出入记录管理系统实现
java·spring boot·后端
hty624 小时前
Spring Boot 注解式大文件 Excel 导入工具:excel‑import‑spring‑boot‑starter
java
李少兄4 小时前
解决IntelliJ IDEA 项目名称后带中括号问题(模块名不一致)
java·ide·intellij-idea