Check whether a string is not null and not empty

后端 未结 30 2032
予麋鹿
予麋鹿 2020-11-22 02:13

How can I check whether a string is not null and not empty?

public void doStuff(String str)
{
    if (str != null && str != \"**here I want to check          


        
30条回答
  •  伪装坚强ぢ
    2020-11-22 03:03

    The better way to handle null in the string is,

    str!=null && !str.equalsIgnoreCase("null") && !str.isEmpty()
    

    In short,

    str.length()>0 && !str.equalsIgnoreCase("null")
    

提交回复
热议问题