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 搜索,有没有某个字段,而不是用眼睛在哪瞅

相关推荐
豆沙沙包?2 小时前
C++~~~stack容器、queue容器、list容器(p45-P56)
c++·windows·list
M78佐菲4 小时前
c语言学习笔记:排序与查找方法整理
linux·c语言·笔记·学习·算法
ltl5 小时前
QUIC 协议拆解(上):为什么 TCP 改不动了
linux
Linux-lucky7 小时前
28-Linux学习之旅之Maven与Nexus制品库
linux·运维·学习·nginx·tomcat·maven
敲代码还房贷9 小时前
VMware17 + Ubuntu22.04 共享 完整步骤
linux·python·ubuntu
King of fraud9 小时前
Linux 下 MySQL 基础操作:创建用户、数据库与权限管理实战
linux·数据库·mysql
戒了,最后一次9 小时前
DeepSeek Harness 源码安装教程(Windows 篇)
windows·腾讯云·deepseek·harness
进击的_鹏10 小时前
从零开始的 Redis 学习
服务器·数据库·c++·redis·缓存
实心儿儿10 小时前
Linux —— 传输层协议TCP
linux·服务器·tcp/ip
祖力5510 小时前
Linux应用软件编程:目录IO与framebuffer
linux·运维·算法·framebuffer·目录io