1、导入maven坐标:

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

2、StringUtils

//对String类型的字符串进行判空
String s = "今天天气正好";
StringUtils.isNotBlank(s);
StringUtils.isEmpty(s);

3.CollectionUtils

//对单列集合Collection判空
List array = new ArrayList();
CollectionUtils.isNotEmpty(array); 

4.MapUtils

//在Map集合中根据key取value,内部都会做一个隐式判空
Map<String,Object> map = new HashMap();
map.put("str","字符串");
map.put("array",new ArrayList<>());
map.put("mapChild","new HashMap()");
String str = MapUtils.getString(map,"str");
List array = (List) MapUtils.getObject(map,"array");
Map mapChild = MapUtils.getMap(map,"mapChild");

  

相关文章:

  • 2022-02-09
  • 2022-12-23
  • 2022-12-23
  • 2021-06-05
  • 2022-12-23
  • 2021-03-31
  • 2022-12-23
猜你喜欢
  • 2021-05-22
  • 2022-12-23
  • 2022-12-23
  • 2021-07-09
相关资源
相似解决方案