how to check if string is empty in if condition in java code example
Example 1: check if string is null or empty java
if(str != null && !str.isEmpty()) { /* do your stuffs here */ }
Example 2: java string util if empty default
String emptyString = new String();
result = StringUtils.defaultIfEmpty(emptyString, "default");
System.out.println(result);
String nullString = null;
result = StringUtils.defaultIfEmpty(nullString, "default");
System.out.println(result);