String 字符串
//直接用字符串调用方法 str.isEmpty() 如果为null则会抛出异常
if (StringUtils.isEmpty(str)){// "" 和null均判断为空
System.out.println("string为空");
}
对象
//第1种:
if (Objects.isNull(null)){ //null
System.out.println("obj为空");
}
//第2种:
if (StringUtils.isEmpty(null)){
System.out.println("obj为空");
}
- 6
- 7
- 8
数组
//数组需要判断null和长度length(大小size)
if (arr == null || arr.length == 0){
System.out.println("arr为空");
}
- 1
- 2
- 3
- 4
list set用法同list
//isEmpty()方法内部就是判断size大小
if (list.isEmpty() && list == null){
System.out.println("list为空");
}
//使用spring提供的工具类
List list=null;
if (CollectionUtils.isEmpty(list)){
System.out.println("list为空");
}
- 6
- 7
- 8
- 9

![[手游] 三网H5小游戏【少年仙路】WIN系服务端+Linux手工服务端+详细搭建教程](https://cdn.jxasp.com:9143/image/20260615/136BC33AA47EB0D84E878835A8B38FDB.png)

















