当前位置:网站首页>list大集合等比分割成多个小list集合
list大集合等比分割成多个小list集合
2022-07-01 18:47:00 【码农巅峰】
一:实体对象准备
package cn.nhdc.cloud.common.annotation;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@NoArgsConstructor
@AllArgsConstructor
@Data
@Builder
public class Order {
/**
* 订单id
*/
private String orderId;
/**
* 订单名称
*/
private String orderName;
}
二:测试案例
package cn.nhdc.cloud.common.annotation;
import cn.hutool.core.collection.ListUtil;
import java.util.ArrayList;
import java.util.List;
public class Test11 {
public static void main(String[] args) {
List<Order> orders = new ArrayList<Order>() {
{
add(Order.builder().orderId("1").orderName("订单1").build());
add(Order.builder().orderId("2").orderName("订单2").build());
add(Order.builder().orderId("3").orderName("订单3").build());
add(Order.builder().orderId("4").orderName("订单4").build());
add(Order.builder().orderId("5").orderName("订单5").build());
add(Order.builder().orderId("6").orderName("订单6").build());
add(Order.builder().orderId("7").orderName("订单7").build());
}};
List<List<Order>> partition = ListUtil.partition(orders, 2);
System.err.println(partition);
List<List<Order>> split = ListUtil.split(orders, 3);
System.err.println(split);
}
}
三:运行结果
[
[Order(orderId=1, orderName=订单1), Order(orderId=2, orderName=订单2)],
[Order(orderId=3, orderName=订单3), Order(orderId=4, orderName=订单4)],
[Order(orderId=5, orderName=订单5), Order(orderId=6, orderName=订单6)],
[Order(orderId=7, orderName=订单7)]
]
[
[Order(orderId=1, orderName=订单1), Order(orderId=2, orderName=订单2), Order(orderId=3, orderName=订单3)],
[Order(orderId=4, orderName=订单4), Order(orderId=5, orderName=订单5), Order(orderId=6, orderName=订单6)],
[Order(orderId=7, orderName=订单7)]
]
边栏推荐
- MySQL reports an error can't create table 'demo01 tb_ Student‘ (errno: 150)*
- JS的Proxy
- Opencv video quality diagnosis - VIDEO occlusion diagnosis
- JVM memory model
- P2433 [deep foundation 1-2] primary school mathematics n in one
- torch. nn. functional. Interpolate function
- 118. Yanghui triangle
- Class loading mechanism
- [research data] observation on the differences of health preservation concepts among people in 2022 - Download attached
- Linux下安装Redis,并配置环境
猜你喜欢

Crunch简介、安装,使用Crunch制作密码字典

Shell advanced

墨天轮沙龙 | 清华乔嘉林:Apache IoTDB,源于清华,建设开源生态之路

GB28181之SIP协议
![[research data] observation on the differences of health preservation concepts among people in 2022 - Download attached](/img/50/926cc5bce83f8b195b3e2072b656bf.jpg)
[research data] observation on the differences of health preservation concepts among people in 2022 - Download attached

再回顾集合容器

【AI服务器搭建】CUDA环境

Why has instagram changed from a content sharing platform to a marketing tool? How do independent sellers use this tool?

uni-app商品分类

实例讲解将Graph Explorer搬上JupyterLab
随机推荐
IPv4地址、子网掩码、网关
optaplanner学习笔记(一)案例Cloud balance
February 15, 2022: sweeping robot. There is a floor sweeping robot in the room (represented by a grid). Each grid in the grid has two possibilities: empty and obstacles. The sweeping robot provides fo
Shell高级进阶
Salesmartly has some tricks for Facebook chat!
H264编码profile & level控制
Linux下安装Redis,并配置环境
win10下使用msys+vs2019编译ffmpeg源码
Analysis of GetMessage underlying mechanism
JVM内存模型
CMU AI PhD first year summary
Difference between redo and undo
axure不显示元件库
集合对象值改变NULL值对象
事务隔离级别 gap锁 死锁
Wechat applet navigator has a shadow after clicking. Remove the shadow effect of navigator
ffmpeg 音频相关命令
Collation of open source protocols of open source frameworks commonly used in Web Development
自定义插入页面标签以及实现类似通讯录的首字母搜索
为什么一定要从DevOps走向BizDevOps?