Check whether a string is not null and not empty

后端 未结 30 2641
予麋鹿
予麋鹿 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:05

    For completeness: If you are already using the Spring framework, the StringUtils provide the method

    org.springframework.util.StringUtils.hasLength(String str)
    

    Returns: true if the String is not null and has length

    as well as the method

    org.springframework.util.StringUtils.hasText(String str)
    

    Returns: true if the String is not null, its length is greater than 0, and it does not contain whitespace only

提交回复
热议问题