public static String defaultIfEmpty(String str,
String defaultStr)
如果str为空,则返回defaultStr。否则返回str;
附官方解释:
defaultIfEmpty
public static String defaultIfEmpty(String str, String defaultStr)
Returns either the passed in String, or if the String is empty or null, the value of defaultStr.
-
StringUtils.defaultIfEmpty(null, "NULL") = "NULL" StringUtils.defaultIfEmpty("", "NULL") = "NULL" StringUtils.defaultIfEmpty("bat", "NULL") = "bat" StringUtils.defaultIfEmpty("", null) = null
-
-
Parameters:
-
str- the String to check, may be null -
defaultStr- the default String to return if the input is empty ("") or null, may be null
Returns:
- the passed in String, or the default
-