Check whether a string is not null and not empty

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

    You should use org.apache.commons.lang3.StringUtils.isNotBlank() or org.apache.commons.lang3.StringUtils.isNotEmpty. The decision between these two is based on what you actually want to check for.

    The isNotBlank() checks that the input parameter is:

    • not Null,
    • not the empty string ("")
    • not a sequence of whitespace characters (" ")

    The isNotEmpty() checks only that the input parameter is

    • not null
    • not the Empty String ("")

提交回复
热议问题