Check whether a string is not null and not empty

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

    It is a bit too late, but here is a functional style of checking:

    Optional.ofNullable(str)
        .filter(s -> !(s.trim().isEmpty()))
        .ifPresent(result -> {
           // your query setup goes here
        });
    

提交回复
热议问题