注意:1. StringUtils.isEmpty() 方法判断空格的情况
import org.springframework.util.StringUtils;
public class TestString {
public static void main(String[] args) {
boolean empty1 = StringUtils.isEmpty(null);
boolean empty2 = StringUtils.isEmpty("");
boolean empty3 = StringUtils.isEmpty(" "); //false
boolean text1 = StringUtils.hasText(null);
boolean text2 = StringUtils.hasText("");
boolean text3 = StringUtils.hasText(" "); //false
// 统计一个子字符串在字符串出现的次数
int i1 = StringUtils.countOccurrencesOf("erowoiueoiur", "e");
int i2 = StringUtils.countOccurrencesOf("erowoiueoiur", "oiur");
//字符串替换
String inString = "a6AazAaa77abaa";
String oldPattern = "aa";
String newPattern = "foo";
String s = StringUtils.replace(inString, oldPattern, newPattern);
//删除字符串
String tarString = "Thejumpedthelazydog";
String noThe = StringUtils.delete(tarString, "the"); //Thejumpedlazydog
System.out.println("empty1:"+empty1);
System.out.println("empty2:"+empty2);
System.out.println("empty3:"+empty3);
System.out.println("text1:"+text1);
System.out.println("text2:"+text2);
System.out.println("text3:"+text3);
System.out.println("i1:"+i1);
System.out.println("i2:"+i2);
System.out.println(s);
System.out.println(noThe);
}
}