当前位置:网站首页>list分为多个子list集合
list分为多个子list集合
2022-07-21 10:30:00 【haohaounique】
需求:当list长度过长而需要切分场景
可用google goouva工具包中的切分
/**
* 将list切分为合适长度的list
* @param list 被切分list
* @param len 切分长度
* @param <T>
* @return
*/
public static <T> List<List<T>> splitList(List<T> list, int len) {
if (list == null || list.size() == 0) {
return null;
}
if (len < 1) {
throw new RuntimeException("截取长度不能小于1");
}
int size = list.size();
int count = (size + len - 1) / len;
List<List<T>> result = new ArrayList<>(count);
for (int i = 0; i < count; i++) {
List<T> subList = new ArrayList<>(list.subList(i * len, ((i + 1) * len > size ? size : (len * (i + 1)))));
result.add(subList);
}
return result;
}
边栏推荐
- 动态创建对象时候为什么使用new,而不是malloc
- 网络数据包的封包格式
- 即刻报名|如何降低云上数据分析成本?
- Multi process single thread multi port TCPUDP three-layer protocol forwarding
- mysql创建新用户并授权
- MySQL storage engine Encyclopedia
- Self made CA certificate for configuring SSL
- Codeforces round 579 (Div. 3) C - common divisors [number theory]
- From scratch implement crnn using pytorch: read training data
- 关于res目录下图片引起的OOM解决方法
猜你喜欢
Cloud native sig live broadcast: About CNI and hybridnet core technology sharing | issue 35
打造一个生命周期感知的MVP架构
MySQL 45 Lecture Notes - string prefix index & MySQL dirty page analysis
网络开发包 libpcap
CMake系列教程2-HelloWorld
vivo官网APP全机型UI适配方案
行业分析| 物流对讲
【性能优化】MySQL常用慢查询分析工具
【论文笔记】ObjectBox: From Centers to Boxes for Anchor-Free Object Detection
Detailed explanation of depthwise separable revolution
随机推荐
方舟编译器来了,APK加固还怎么搞
Detailed explanation of depthwise separable revolution
[MySQL] what if you forget your password?
matplotlib. Pyplot interface summary
Vivo official website app full model UI adaptation scheme
开启关闭线程的封装类
【机器学习】Kmeans聚类
【Mysql】忘记密码怎么办?
Open and close the encapsulated class of the thread
matplotlib(六)三维作图
MySQL45讲笔记-字符串前缀索引&MySQL刷脏页分析
Digitalization of museums - development of digital collections app
【性能优化】MySQL常用慢查询分析工具
B站自定义倍数代码
剑指 Offer 46. 把数字翻译成字符串
C: File encryption
关于res目录下图片引起的OOM解决方法
Industry analysis | logistics intercom
2019 Niuke summer multi school training camp (the sixth session) d-move [violence enumeration]
2022全球开发者薪资曝光:中国排第19名,平均年薪23,790美元