赞
踩
字符串工具类StringUtils
字符串工具类
String str="hahahaha";
/*判断字符串是否为 null,或 ""。注意,包含空白符的字符串为非空
boolean isEmpty (Object str)*/
if (StringUtils.isEmpty(str)) {
log.info("str is null");
}
/* 判断字符串是否是以指定内容结束。忽略大小写
boolean endsWithIgnoreCase (String str, String suffix)*/
if (StringUtils.endsWithIgnoreCase(str, "aha")) {
log.info("str is endsWith aha");
}
/* 判断字符串是否已指定内容开头。忽略大小写
boolean startsWithIgnoreCase (String str, String prefix)*/
if (StringUtils.startsWithIgnoreCase(str, "ha")) {
log.info("str is startsWith ha");
}
/* 是否包含空白符
boolean containsWhitespace (String str)*/
if (StringUtils.containsWhitespace(str)) {
log.info("str is contains whitespace");
}
/*判断字符串非空且长度不为 0,即,Not Empty
boolean hasLength (CharSequence str)*/
if (StringUtils.hasLength(str)) {
log.info("str is hasLength");
}
/*判断字符串是否包含实际内容,即非仅包含空白符,也就是 Not Blank
boolean hasText (CharSequence str)*/
if (StringUtils.hasText(str)) {
log.info("str is hasText");
}
/*判断字符串指定索引处是否包含一个子串。
boolean substringMatch (CharSequence str,int index, CharSequence substring)*/
if (StringUtils.substringMatch(str, 0, "ha")) {
log.info("str is substringMatch");
}
/*计算一个字符串中指定子串的出现次数
int countOccurrencesOf (String str, String sub)*/
if (StringUtils.countOccurrencesOf(str, "ha") == 2) {
log.info("str is countOccurrencesOf");
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。