java判空

1 字符串判空(org.apache.commons.lang3

  1. StringUtils.isEmpty() 判断null 和 空字符串,不能判断空格
	   StringUtils.isEmpty(null)      = true
       StringUtils.isEmpty("")        = true
       StringUtils.isEmpty(" ")       = false
       StringUtils.isEmpty("bob")     = false
       StringUtils.isEmpty("  bob  ") = false
  1. StringUtils.isBlank() 判断null 和 空字符串,增加只有空格也算为空
       StringUtils.isBlank(null)      = true
       StringUtils.isBlank("")        = true
       StringUtils.isBlank(" ")       = true
       StringUtils.isBlank("bob")     = false
       StringUtils.isBlank("  bob  ") = false

2 对象判空(package java.util

Objects.isNull()

3 集合判空(org.springframework.util

CollectionUtils.isEmpty()包括null 和 大小为0

猜你喜欢

转载自blog.csdn.net/Ssucre/article/details/119958736