Can we rely on String.isEmpty for checking null condition on a String in Java?

前端 未结 6 2352
南旧
南旧 2020-12-24 10:44

I am passing an accountid as input from an XML file as shown, which will be parsed later and will be used in our code:

123456         


        
6条回答
  •  醉梦人生
    2020-12-24 11:17

    Use StringUtils.isEmpty instead, it will also check for null.

    Examples are:

     StringUtils.isEmpty(null)      = true
     StringUtils.isEmpty("")        = true
     StringUtils.isEmpty(" ")       = false
     StringUtils.isEmpty("bob")     = false
     StringUtils.isEmpty("  bob  ") = false
    

    See more on official Documentation on String Utils.

提交回复
热议问题