1 判断2个对象是否相等
Objects.equals(a, b)
(1) 比较时, 若a 和 b 都是null, 则返回 true, 如果a 和 b 其中一个是null, 另一个不是null, 则返回false。注意:不会抛出空指针异常。
(2) a 和 b 如果都是空值字符串:"", 则 a.equals(b), 返回的值是true, 如果a和b其中有一个不是空值字符串,则返回false;
2 JAVA 7 的 null 检查,方便追踪异常
![](https://img-blog.csdnimg.cn/img_convert/cb7b3d24de282cd707290f990887b15c.png)
3 JAVA 8 的非空判断
Objects.nonNull(Object obj) 非空判断
Objects.isNull(Object obj) 空判断
4 字符串的超常用的处理
(1)拼接多个字符串
![](https://img-blog.csdnimg.cn/img_convert/c99e69735f03309ecd383fd56fffb1a2.png)
String.join(",", picUrls) 可以为一个集合类型
String.concat()单个拼接
(2)流式处理法:将集合字符串类型转进行拼接
customerGroup.setOwnerName(customers.stream().filter(s -> CustomerIdentityEnum.OWNER.itemCode.equals(s.getType())).map(Customer::getName).collect(Collectors.joining(Constant.COMMA_DELIMITER)));
(3)反操作:将字符串拆解为集合类型(以逗号分割的String)
流式处理法:
Set<String> ids = Arrays.stream(candidateIds.toString().split(",")).filter(a -> StringUtils.isNotBlank(a)).collect(Collectors.toSet());
函数法:
List<String> result = Arrays.asList(string.split(","));
![](https://img-blog.csdnimg.cn/img_convert/29eed301b068443f379cc8cb42253618.png)
(4)字符串工具类
org.apache.commons.lang3.StringUtils;
非空判断 。。。。 等等
StringUtils.isNotBlank(wfTaskDTO.getExecuteEmployeeId())
当然返回给前端的字符串可以通过注释来解析。
5 对于返回的option 对象的处理
在使用流操作后返回的数据对象:
![](https://img-blog.csdnimg.cn/img_convert/b5436d87acb38cb26d2b6d4e85207323.png)
![](https://img-blog.csdnimg.cn/img_convert/a39374c4b4a8060ec9e70f59223d241a.png)
![](https://img-blog.csdnimg.cn/img_convert/08362857a6868e2e63b63360f9cfd3b1.png)
6 stream 流运算
可以针对map,List集合 ,数组 创建stream 流; 可以进行操作;
![](https://img-blog.csdnimg.cn/img_convert/fe2eae837b753d0a2e8d7e1b6a04f357.png)
ps: 当你在使用一些常用的工具时,不要想着去重复造轮子,而要去查一下是否已经有了轮子,大部分通用的工具类都有轮子,比如hutool 工具。