StringUtils.isBlank()方法把空格当做没有,个人常用。
StringUtils.isEmpty()认可空格的存在。
有一个为空true
StringUtils.isAnyBlank()
所有都不为空true
StringUtils.isNoneBlank()
判断字符串大写、小写
StringUtils.isAllUpperCase(“ABC”);//—true
StringUtils.isAllLowerCase(“abC”);//—false
判断是否为空(注:isBlank与isEmpty 区别)
StringUtils.isBlank(null);//—true
StringUtils.isBlank("");//—true
StringUtils.isBlank(" ");//—true
删除字符串中的所有空格
StringUtils.deleteWhitespace(" ab c ");//—“abc”
判断两字符串是否相同
StringUtils.equals(“abc”, “abc”);//—true
StringUtils.equalsIgnoreCase(“abc”, “ABC”);//—true
判断一字符串是否包含另一字符串
StringUtils.contains(“abc”, “z”);//—false
StringUtils.containsIgnoreCase(“abc”, “A”);//—true
判断字符串数字
StringUtils.isNumeric(“123”);//—true
StringUtils.isNumeric(“12 3”);//—false (不识别运算符号、小数点、空格……)
StringUtils.isNumericSpace(“12 3”);//—true
大小写转换
StringUtils.upperCase(“aBc”);//—“ABC”
StringUtils.lowerCase(“aBc”);//—“abc”
去除字符串中的"\n", “\r”, or “\r\n”
StringUtils.chomp(“abc\r\n”);//—“abc”
统计一字符串在另一字符串中出现次数
StringUtils.countMatches(“abba”, “a”);//—2
检查字符串结尾后缀是否匹配
StringUtils.endsWith(“abcdef”, “def”);//—true
StringUtils.endsWithIgnoreCase(“ABCDEF”, “def”);//—true
StringUtils.endsWithAny(“abcxyz”, new String[] {null, “xyz”, “abc”});//—true
检查起始字符串是否匹配
StringUtils.startsWith(“abcdef”, “abc”);//—true
StringUtils.startsWithIgnoreCase(“ABCDEF”, “abc”);//—true
StringUtils.startsWithAny(“abcxyz”, new String[] {null, “xyz”, “abc”});//—true
NumberUtils:
从数组中选出最大值
NumberUtils.max(new int[] { 1, 2, 3, 4 });//—4
判断字符串是否全是整数
NumberUtils.isDigits(“153.4”);//–false
判断字符串是否是有效数字
NumberUtils.isCreatable("");
校验提供的字符串是否可以解析为number
NumberUtils.isParsable("")
说明:可解析的number包括下面方法可以执行字符串 Integer.parseInt(String), Long.parseLong(String), Float.parseFloat(String) , Double.parseDouble(String)。十六进制和科学计数符号认为是不可解析的。
DateUtils:
判断是否同一天
DateUtils.isSameDay(date1, date2);
lzx记录于20200507