mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add nullIfBlank
This commit is contained in:
@@ -153,6 +153,18 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
return isEmpty(str) ? null : str;
|
return isEmpty(str) ? null : str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当给定字符串为空字符串时,转换为{@code null}
|
||||||
|
*
|
||||||
|
* @param <T> 字符串类型
|
||||||
|
* @param str 被转换的字符串
|
||||||
|
* @return 转换后的字符串
|
||||||
|
* @since 6.0.0
|
||||||
|
*/
|
||||||
|
public static <T extends CharSequence> T nullIfBlank(final T str) {
|
||||||
|
return isBlank(str) ? null : str;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>如果给定字符串为{@code null}返回默认值
|
* <p>如果给定字符串为{@code null}返回默认值
|
||||||
* <pre>{@code
|
* <pre>{@code
|
||||||
|
Reference in New Issue
Block a user