20230829工作心得:如何把大List 切割为多个小List?

1 怎么看这个方法谁在调用它?

解决:按ctrl,然后点进去看。

idea里看方法的具体细节,和谁在调用这个方法,都可以通过按ctrl,然后单击查看。

2 请求的时候,如果时间yyyy-MM-dd HH:mm:ss在url里会报错?有非法字符。

解决:可以在空格的位置拼上%20,像这样:

//这里date是LocalDateTime格式

date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd%20HH:mm:ss")))

3 string 变 integer 。不要强转 。

解决:

Integer.valueOf("string字符串");

//或者

Integer.parseInt("string字符串");//这个结果是int,但你也可以直接赋值给Integer对象,因为Java5之后,就引用了自动装箱和拆箱。

4 修改原list .lambda表达式

优雅解决 : 更新list里每个Person对象的age

// 假设有一个包含Person对象的列表

List<Person> updatedList = personList.stream() .map(a -> { a.setAge(1); return a; }) .collect(Collectors.toList());

注意:如果这样写,就是把list里每个对象的age提取出来,变成list

// 假设有一个包含Person对象的列表

List<Person> updatedList = personList.stream() .map(a -> a.getAge()) .collect(Collectors.toList());

5 把大List 切割为 更小尺寸的小List?

优雅解决 : Lists.partition(原list,目标数量)

import com.google.common.collect.Lists;

// 原始列表

List<Integer> originalList = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);

// 子列表长度

int partitionSize = 100;

List<List<Integer>> subLists = Lists.partition(originalList, partitionSize);

// 输出切割后的子列表

for (List<Integer> subList : subLists) {

System.out.println(subList);

}

6 配置信息要记录一下,修改哪些@Value以及XXL_JOB相关参数。

7 时间 每10分钟执行,XXL_JOB传参

startTime = LocalDateTime.now().minusMinutes(11);

endTime = LocalDateTime.now();

昨天文章提到《20230828工作日志》,要用JSON格式化工具看JSON字符串结果,

8 除此以外,要擅用 ctrl+F 搜索,有没有某个字段,而不是用眼睛在哪瞅

相关推荐
北京中科新远科技19 小时前
AI集群交换网络容量怎么算:端口、收敛比与Leaf-Spine验收
服务器·网络·人工智能
wdfk_prog19 小时前
Wi-Fi Direct 教程 04:Interface 协议子系统初始化——WPA/EAPOL、WPS、DPP/NAN、GAS 与 P2P callback
android·运维·服务器·ubuntu·p2p·wps·wifi-direct
云飞云共享云桌面19 小时前
有个10人的SolidWorks设计团队,服务器什么配置合适,如何落地
运维·服务器·3d·自动化·电脑·制造
cuijiecheng201819 小时前
RK3588 DEP 接入 Dante Domain Manager(DDM)完整测试记录
linux
爱吃香菜的初学者19 小时前
十二.Linux——管道
linux·运维·服务器
网硕互联的小客服1 天前
Linux服务器磁盘应该如何合理分区?
linux·运维·服务器
lisanmengmeng1 天前
nacos nrpe 监控机及被监控机部署
服务器·nacos·nagios·nrpe
段一凡-华北理工大学1 天前
大模型应用开发 100 天:Python + LLM 从入门到精通 day26~Prompt 调试与优化——A/B 测试与效果评估
windows·python·大模型·prompt·智能体·提示词工程·高炉智能化
贵沫末1 天前
Ubuntu——常用软件安装
linux·运维·ubuntu
Doraemomo1 天前
Linux内核驱动开发——中断与定时器
linux·运维·驱动开发