org.apache.commons.lang.StringUtils 常用方法

isEmpty 判断为空或长度为0
isNotEmpty 判断不为空且长度大于0
isEmpty 等价于 str == null || str.length == 0
isNotEmpty 等价于 str != null && str.length > 0 (与isEmpty相反)

isBlankisEmpty 区别:isBlank 去除空格后判断
isBlank 等价于 str == null || str.length == 0 || str.trim().length == 0
isNotBlank 等价于 str != null && str.length > 0 && str.trim().length > 0 (与isBlank相反)

trim String 的 trim 的作用一样,去除字符串前后空格
trimToNull      先去除前后空格,然后判断内容是否为空,如果内容为空,则是 null
trimToEmpty  判断字符串是否为 null ,如果是,则直接返回 "",否则,去除字符串前后空格后返回

contains(a, b)   判断字符串a里是否包含了b

join(new String[]{"dog", "cat", "monkey"}, ":"); 把数组的元素使用 : 进行拼接

split("apple|xiaomi|dell|lenovo", "|");  根据特定分隔符对字符串进行拆分

capitaliseAllWords("today i will go to china");  所有单词首字母大写

countMatches("Happy Birthday to you", "o");  统计某个字符串在字符串出现的次数

leftPad("54", 8, "0"); 结果00000054  必须要8位,不够的就拿0去字符串左边补

rightPad("54", 8, "0");结果54000000  必须要8位,不够的就拿0去字符串右边补

startsWith("GoodMorning", "go");  判断字符串是否以特定字符串开头,区分大小写

endsWith("GoodMorning", "ing");  判断字符串是否以特定字符串开头,区分大小写

 

你可能感兴趣的:(Java)