Check whether a string is not null and not empty

后端 未结 30 2049
予麋鹿
予麋鹿 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 02:48

    As seanizer said above, Apache StringUtils is fantastic for this, if you were to include guava you should do the following;

    public List findEmployees(String str, int dep) {
     Preconditions.checkState(StringUtils.isNotBlank(str), "Invalid input, input is blank or null");
     /** code here **/
    }
    

    May I also recommend that you refer to the columns in your result set by name rather than by index, this will make your code much easier to maintain.

提交回复
热议问题