Add emptyToNull & nullToEmpty (#597)

pull/602/head
chen.ma 2 years ago
parent 93bec5411f
commit 77d5f88a49

@ -26,6 +26,26 @@ public class StringUtil {
public static final char UNDERLINE = '_';
/**
* Returns the given string if it is nonempty; {@code null} otherwise.
*
* @param str
* @return
*/
public static String emptyToNull(String str) {
return (str == null || str.isEmpty()) ? null : str;
}
/**
* Returns the given string if it is non-null; the empty string otherwise.
*
* @param str
* @return
*/
public static String nullToEmpty(String str) {
return str == null ? "" : str;
}
/**
* Is blank.
*

Loading…
Cancel
Save