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
With Java 8 Optional you can do:
public Boolean isStringCorrect(String str) { return Optional.ofNullable(str) .map(String::trim) .map(string -> !str.isEmpty()) .orElse(false); }
In this expression, you will handle Strings that consist of spaces as well.
String