检查字符串是否为空或null或仅仅包含空格
String test = ""; String test1=" "; String test2 = "\n\n\t"; String test3 = null; System.out.println( "test blank? " + StringUtils.isBlank( test ) ); System.out.println( "test1 blank? " + StringUtils.isBlank( test1 ) ); System.out.println( "test2 blank? " + StringUtils.isBlank( test2 ) ); System.out.println( "test3 blank? " + StringUtils.isBlank( test3 ) ); 运行结果: test blank? true test1 blank? true test2 blank? true test3 blank? true 相对应的还有一个StringUtils.isNotBlank(String str) StringUtils.isEmpty(String str)则检查字符串是否为空或null(不检查是否仅仅包含空格) 分解字符串 StringUtils.split(null, *, *) = null StringUtils.split("", *, *) = [] StringUtils.split("ab de fg", null, 0) = ["ab", "cd", "ef"] StringUtils.split("ab de fg", null, 0) = ["ab", "cd", "ef"] StringUtils.split("ab:cd:ef", ":", 0) = ["ab", "cd", "ef"] StringUtils.split("ab:cd:ef", ":", 1) = ["ab:cd:ef"] StringUtils.split("ab:cd:ef", ":", 2) = ["ab", "cd:ef"] StringUtils.split(String str,String separatorChars,int max) str为null时返回null separatorChars为null时默认为按空格分解,max为0或负数时分解没有限制,max为1时返回整个字符串,max为分解成的个数(大于实际则无效) 去除字符串前后指定的字符 StringUtils.strip(null, *) = null StringUtils.strip("", *) = "" StringUtils.strip("abc", null) = "abc" StringUtils.strip(" abc ", null) = "abc" StringUtils.strip(" abcyx", "xyz") = " abc" StringUtils.strip(String str,String stripChars) str为null时返回null,stripChars为null时默认为空格 创建醒目的Header(调试时用) 字符的全部反转及以单个词为单位的反转 检查字符串是否仅仅包含数字、字母或数字和字母的混合 |
|