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

[[水星, 金星, 地球, 火星, 冥王星], 
[土星, 天王星, 海王星, 冥王星, 木星]]
相关推荐
轮到我狗叫了23 分钟前
力扣.1471数组的k个最强值,力扣.1471数组的k个最强值力扣1576.替换所有的问号力扣1419.数青蛙编辑力扣300.最长递增子序列
java·数据结构·算法
秋野酱34 分钟前
基于SpringBoot的家政服务系统设计与实现(源码+文档+部署讲解)
java·spring boot·后端
趁你还年轻_36 分钟前
常用的Java工具库
java
敲代码的瓦龙36 分钟前
STL?list!!!
c语言·开发语言·数据结构·c++·windows·list
一枚小菜程序员38 分钟前
记录: Windows下远程Liunx 系统xrdp 用到的一些小问题(免费踩坑 记录)
windows
不再幻想,脚踏实地42 分钟前
Spring Boot 日志
java·spring boot·后端
风象南1 小时前
SpringBoot中10种动态修改配置的方法
java·spring boot·后端
金斗潼关1 小时前
基于OAuth2+SpringSecurity+Jwt实现身份认证和权限管理后端服务
java·鉴权
代码小将4 小时前
Leetcode209做题笔记
java·笔记·算法
专注_每天进步一点点4 小时前
idea 启动Springboot项目在编译阶段报错:java: OutOfMemoryError: insufficient memory
java·spring boot·intellij-idea