当前位置:网站首页>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)]
]
边栏推荐
猜你喜欢

Why must we move from Devops to bizdevops?

HLS4ML进入方法

自定义插入页面标签以及实现类似通讯录的首字母搜索

GC垃圾回收

Oracle physical architecture

DTD modeling

Regular expression =regex=regular expression

毕业季 | 华为专家亲授面试秘诀:如何拿到大厂高薪offer?

Introduction and installation of crunch, and making password dictionary with crunch

optaplanner学习笔记(一)案例Cloud balance
随机推荐
Anaconda安装虚拟环境到指定路径
Opencv video quality diagnosis - VIDEO occlusion diagnosis
MySQl的基本使用
Optaplanner learning notes (I) case cloud balance
mysql 報錯 Can‘t create table ‘demo01.tb_Student‘ (errno: 150)*
IPv4地址、子网掩码、网关
703. The k-th element in the data flow
GC garbage collection
Shell高级进阶
[SQL optimization] the difference between with as and temporary tables
Ffmpeg common commands (2)
产品模块化设计的前世今生
Introduction and installation of crunch, and making password dictionary with crunch
今日群里分享的面试题
自定义插入页面标签以及实现类似通讯录的首字母搜索
[research materials] national second-hand housing market monthly report January 2022 - Download attached
Wechat applet realizes keyword highlighting
703. 数据流中的第 K 大元素
torch. nn. functional. Interpolate function
【let var const】