mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-08-18 20:38:02 +08:00
StrUtil增加toStringOrEmpty方法
This commit is contained in:
@@ -254,7 +254,7 @@ public class StrUtil extends CharSequenceUtil implements StrPool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 调用对象的toString方法,null会返回{@code null}
|
* 调用对象的toString方法,{@code null}会返回{@code null}
|
||||||
*
|
*
|
||||||
* @param obj 对象
|
* @param obj 对象
|
||||||
* @return 字符串 or {@code null}
|
* @return 字符串 or {@code null}
|
||||||
@@ -264,6 +264,18 @@ public class StrUtil extends CharSequenceUtil implements StrPool {
|
|||||||
return null == obj ? null : obj.toString();
|
return null == obj ? null : obj.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调用对象的toString方法,{@code null}会返回空字符串 ""
|
||||||
|
*
|
||||||
|
* @param obj 对象
|
||||||
|
* @return {@link String }
|
||||||
|
* @author ahwei163@qq.com
|
||||||
|
*/
|
||||||
|
public static String toStringOrEmpty(final Object obj) {
|
||||||
|
// obj为空时, 返回 null 或 "null" 都不适用部分场景, 此处返回 "" 空字符串
|
||||||
|
return null == obj ? EMPTY : obj.toString();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建StringBuilder对象
|
* 创建StringBuilder对象
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user