StringUtils字符串公共处理类

public final class StringUtils {
/**
* Checks if a string is empty ("") or null.
*
* @param str
* string to check, may be null
* @return <code>true</code> if the string is <code>null</code> or empty,
* else <code>false</code>
*/
public static boolean isEmpty(final String str) {
return str == null || str.length() == 0;
}
/**
* Checks if a string is not empty ("") and not null.
*
* @param str
* string to check, may be null
* @return <code>true</code> if the string is not empty and not
* <code>null</code>, else <code>false</code>
*/
public static boolean isNotEmpty(final String str) {
return !isEmpty(str);
}
/**
* Checks if a string is whitespace, empty ("") or null. Whitespace is
* checked by {@link Character#isWhitespace(char)}.
*
* @param str
* string to check, may be null
* @return <code>true</code> if the string is <code>null</code>, empty or
* whitespace
*/
public static boolean isBlank(final String str) {

if (isEmpty(str))
return true;

for (char c : str.toCharArray()) {
if (!Character.isWhitespace(c))
return false;
}

return true;
}
/**
* Checks if a string is not empty (""), not null and not whitespace.
*
* @param str
* string to check, may be null
* @return <code>true</code> if the string is not <code>null</code>, not
* empty and not whitespace.
*/
public static boolean isNotBlank(final String str) {
return !isBlank(str);
}
/**
* Constructs a set of lower-cased strings from a delimiter-separated
* string.
*
* @param stringList
* strings separated with a delimiter
* @param delimiter
* separating delimiter
* @return a lower-cased set, empty set if stringList is empty
* @throws IllegalArgumentException
* if <code>delimiter</code> is empty
*/
public static Set<String> getSet(final String stringList,
final String delimiter) {
if (isEmpty(delimiter))
throw new IllegalArgumentException(
"Argument 'delimiter' shouldn't be empty!");
if (isEmpty(stringList))
return new HashSet<String>();

Set<String> set = new HashSet<String>();
String[] strs = stringList.split(delimiter);
for(int i=0;i<strs.length;i++) {
String tmp = strs[i];
if(isNotEmpty(tmp)) {// simple empty filter
set.add(tmp.toLowerCase());
}
}
return set;
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值