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;
}
}
分享到:
相关推荐
commons-lang3-3.1 StringUtils字符串jar包 org.apache.commons.lang3.StringUtils的jar包
NULL 博文链接:https://xylonwang.iteye.com/blog/467843
主要介绍了Java StringUtils字符串分割转数组的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
java 更加详细的字符串处理工具类,例如html标签格式化长度处理非常多的工具
StringUtils 字符串工具类,基本上是封装的commons.lang3.StringUtils,有需要的可以下载看下
主要为大家详细介绍了javaScript字符串工具类StringUtils,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
web项目中常用的字符串操作类,可以直接下载后,修改包名就可以了
判断字符串为空 判断Email有效性 判断身份证号码有效性 判断手机号码有效性 判断是否含有特殊字符 校验是否是中文名字 包括 姓名 • 校验是否是英文名字 将字符串转换为大写 将字符串转换为小写 判断字符串是否为...
StringUtils工具类的使用工具类的使用
除了Java本身的字符串处理方式外,我们还可以使用Apache Common Langs里的StringUtils来简化String的操作。但以上两种方式对于我们日常编程中最容易碰到的字符串处理来说,仍然显得有些不足。所以这篇文章给大家介绍...
org.apache.commons.lang3.StringUtils的jar包,判断字符串为空
此帮助类是判断字符串为空,包括(null,"","null"),在写代码时有非常大的帮助,具体使用详见:https://www.jianshu.com/p/a1fa86a710c0
java String工具类,继承自org.apache.commons.lang3.StringUtils,并优化
jar包中的StringUtils类用于操作字符串的各种判断和截取
由于切片只需指定偏移量和长度,因此复制和处理切片比复制和处理它们引用的字符串要便宜得多。 为了进一步降低天然气成本,切片上需要返回切片的大多数功能都修改了原来的功能,而不是分配新的功能。 例如, s....