Check whether a string is not null and not empty

后端 未结 30 2452
予麋鹿
予麋鹿 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 02:48

    If you use Spring framework then you can use method:

    org.springframework.util.StringUtils.isEmpty(@Nullable Object str);
    

    This method accepts any Object as an argument, comparing it to null and the empty String. As a consequence, this method will never return true for a non-null non-String object.

提交回复
热议问题