集合,对象,字符串 优雅判null

对象优雅判断null

 

使用ObjectUtils.allNotNull()和StringUtils.equals(),比较值是否为空以及比较值是否相等真的很舒服

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
    <version>3.9</version>
</dependency>

注意选错的话是不会有相应的功能的,如果使用ObjectUtils.allNotNull(A),其中A不是null,那就返回true,否则返回false,而使用StringUtils.equals(B,C),如果B和C相等,就返回true,否则就会false

 

https://blog.csdn.net/ls490447406/article/details/107124199/

 

集合优雅判断null

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.3</version>
</dependency>

/**
* 6、空安全检查指定的集合是否为空
*/
CollectionUtils.isEmpty(Collection<?> coll)
/**
* 7、 空安全检查指定的集合是否为空。
*/
CollectionUtils.isNotEmpty(Collection<?> coll)

https://blog.csdn.net/qq_38737586/article/details/109826628

 

String 类型优雅判null

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
    <version>3.9</version>
</dependency>

 

StringUtils.isNotEmpty();

 

关于StringUtils的用法:

https://blog.csdn.net/weixin_42290280/article/details/82591161

posted @ 2021-07-08 16:44  wq9  阅读(164)  评论(0)    收藏  举报