PS:首先需要导入,我用的是3.6版本
package ;
import .;/**
* StringUtils常用方法
*
* @author ZYY
*
*/
public class TestStringUtils {
public static void main(String[] args) {
testReplace();
}
/**
* 测试IsBlank
*
*/
public static void testBlank() {
String str = "you are luck!";
// 结果为false
((str));
// 结果为true
((""));
// 结果为true
((null));
对于制表符、换行符、换页符和回车符()均识为空白符
(("\t \n \f \r"));
// true,只要为空白字符都为true
((" "));
// isNotBlank,只要为null或者""都等于false
((""));
}
/**
* 测试isEmpty 只要不是null和""都为true
*/
public static void testEmpty() {
String str = "thanks you";
((str));
// 空白字符为true
((""));
// 空格字符为false
((" "));
// 对于制表符、换行符、换页符和回车符()均识不为空
(("\t \n \f \r"));
((null));
}
/**
* 测试equals 只要内容相同,就返回true
*/
public static void testEquals() {
String s1 = "hello word";
String s2 = "hello word";
String s3 = new String("hello word");
((s1, s2));
((s1, s3));
}
/**
* 测试join 将数组以符号或其他字符串为间隔组成新的字符串
*/
public static void testJoin() {
String[] strs = { "1", "2", "3", "4", "5", "6" };
String join = (strs, "|");
// 1|2|3|4|5|6
(join);
}
/**
* 测试split 把字符串以某个字符分开,返回一个字符串数组
*/
public static void testSplit() {
String str = "1|2|3|4|5|6";
String[] split = (str, '|');
// 结果为1,2,3,4,5,6
for (String string : split) {
(string);
}
}
/**
* 测试TrimToNull 把字符串的开头空格和尾部的空格去掉
*/
public static void testTrimToNull() {
String str = " you are luck ";
String trimToNull = (str);
// "you are luck"
(trimToNull);
}
/**
* 测试replace 对字符串,在其中截取某个字符串替换成某个字符串
*/
public static void testReplace() {
String str = "you is luck";
String replace = (str, "is", "are");
// you is luck
(str);
// you are luck
(replace);
}
}