<dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId></dependency>
实验室:
常用方法:
StringUtils.truncate("abcdefg", 7);StringUtils.wrapIfMissing("ab", 'x');StringUtils.remove("queued", "ue");StringUtils.replace("aba", "a", "");StringUtils.lastIndexOf("sdfafvdsffs", "v");StringUtils.appendIfMissing("sdsf","dfsf");StringUtils.substring("abc", 2);StringUtils.overlay("abcdef", "zzzz", -1, 4);StringUtils.equals("abc", "ABC");
全量的:
String abl = "1,2,3,4,5,6"; // 11String abStr = "axcvabnmlKjhduweiu";// 17String abLagu = "犯我中华者";String abln = "\n";// abbreviate = ax...System.out.println("abbreviate = " + StringUtils.abbreviate(abStr,5));// abbreviate2 = ...nmlk...System.out.println("abbreviate2 = " + StringUtils.abbreviate(abStr,5,10));// abbreviate3 = axcvbnm***System.out.println("abbreviate3 = " + StringUtils.abbreviate(abStr, "***", 2, 10));// 中间替换符 abbreviateMiddle = axc***eiuSystem.out.println("abbreviateMiddle = " + StringUtils.abbreviateMiddle(abStr, "***", 9));// 字符串尾部加指定字符 appendIfMissingIgnoreCase() = axcvbnmlkjhduweiukSystem.out.println("appendIfMissingIgnoreCase() = " + StringUtils.appendIfMissingIgnoreCase(abStr,"k"));// appendIfMissing = 1,2,3,4,5,6,7System.out.println("appendIfMissing = " + StringUtils.appendIfMissing(abl,",7","5"));// appendIfMissing = 犯我中华者,虽远必诛System.out.println("appendIfMissing = " + StringUtils.appendIfMissing(abLagu,",虽远必诛","华"));// appendIfMissingIgnoreCase = 犯我中华者,虽远必诛System.out.println("appendIfMissingIgnoreCase = " + StringUtils.appendIfMissingIgnoreCase(abLagu, ",虽远必诛", "华"));// 首字母达成大写System.out.println("capitalize = " + StringUtils.capitalize(abStr));// center = 犯我中华者System.out.println("center = " + StringUtils.center(abLagu,10));// center = axcvbnmlkjhduweiuSystem.out.println("center = " + StringUtils.center(abStr,3,"shiyi"));// 去除换行符System.out.println("chomp = " + StringUtils.chomp(abln));// 比较大小System.out.println("compare = " + StringUtils.compare("10","11"));// 比较大小 换算之后比System.out.println("compare = " + StringUtils.compare(abStr,abLagu));// 忽略大小写比较System.out.println("compareIgnoreCase = " + StringUtils.compareIgnoreCase("abc","Abc"));// 是否考虑值为null的时候System.out.println("compareIgnoreCasenull = " + StringUtils.compareIgnoreCase("abc","null",false));// 判断字符串是否包含abSystem.out.println("contains = " + StringUtils.contains(abStr,"ab"));// 任意包含System.out.println("containsAny = " + StringUtils.containsAny(abStr,"ab","b"));// 忽略大小写匹配System.out.println("containsIgnoreCase = " + StringUtils.containsIgnoreCase(abStr,"k"));// s在字符串中没有System.out.println("containsNone = " + StringUtils.containsNone(abStr,"s"));//System.out.println("containsOnly = " + StringUtils.containsOnly(abStr,"as"));// 检查是否有空字符 containsWhitespace = trueSystem.out.println("containsWhitespace = " + StringUtils.containsWhitespace("sfds dsf s"));// a 在字符串中出现的次数 countMatches = 2System.out.println("countMatches = " + StringUtils.countMatches(abStr,"a"));// 空字符串替换成null defaultString = nullSystem.out.println("defaultString = " + StringUtils.defaultIfBlank("","null"));// 空字符串替换成null defaultIfEmpty = nullSystem.out.println("defaultIfEmpty = " + StringUtils.defaultIfEmpty("", "null"));// defaultString = zheshikongSystem.out.println("defaultString = " + StringUtils.defaultString(null,"zheshikong"));// 删除空字符串 deleteWhitespace = adfddSystem.out.println("deleteWhitespace = " + StringUtils.deleteWhitespace("a dfd d "));// difference = xyzSystem.out.println("difference = " + StringUtils.difference("ab", "abxyz"));// endsWith = trueSystem.out.println("endsWith = " + StringUtils.endsWith("abcdef", "def"));// equals = falseSystem.out.println("equals = " + StringUtils.equals("abc", "ABC"));// firstNonBlank = xyzSystem.out.println("firstNonBlank = " + StringUtils.firstNonBlank(null, "", " ", "xyz"));// getBytes = 18System.out.println("getBytes = " + StringUtils.getBytes(abStr, "utf-8").length);// getCommonPrefix = abSystem.out.println("getCommonPrefix = " + StringUtils.getCommonPrefix(new String[]{"abcde", "ab"}));// getDigits = 5417543010System.out.println("getDigits = " + StringUtils.getDigits("(541) 754-3010"));// getFuzzyDistance = 2System.out.println("getFuzzyDistance = " + StringUtils.getFuzzyDistance("Workshop", "ws", Locale.ENGLISH));// getIfBlank = nullSystem.out.println("getIfBlank = " + StringUtils.getIfBlank("", () -> null));// 字符串相似度 getJaroWinklerDistance = 0.88System.out.println("getJaroWinklerDistance = " + StringUtils.getJaroWinklerDistance("hello", "hallo"));// getLevenshteinDistance = 7System.out.println("getLevenshteinDistance = " + StringUtils.getLevenshteinDistance("elephant", "hippo", 7));// indexOf = 2System.out.println("indexOf = " + StringUtils.indexOf("aabaabaa", "b"));// indexOfAny = 3System.out.println("indexOfAny = " + StringUtils.indexOfAny("zzabyycdxx", new String[]{"b", "y"}));// indexOfAnyBut = 0System.out.println("indexOfAnyBut = " + StringUtils.indexOfAnyBut("aba", new char[] {'z'} ) );// indexOfDifference = -1System.out.println("indexOfDifference = " + StringUtils.indexOfDifference(new String[]{"abc", "abc"}));// isAllBlank = falseSystem.out.println("isAllBlank = " + StringUtils.isAllBlank(" ", "bar") );// isAllLowerCase = falseSystem.out.println("isAllLowerCase = " + StringUtils.isAllLowerCase("ab1c"));// isAllUpperCase = trueSystem.out.println("isAllUpperCase = " + StringUtils.isAllUpperCase("ABC") );// 检查 CharSequence 是否仅包含 Unicode 字母 isAlpha = trueSystem.out.println("isAlpha = " + StringUtils.isAlpha("abc"));// isMixedCase = trueSystem.out.println("isMixedCase = " + StringUtils.isMixedCase("a/C"));// isNotBlank = falseSystem.out.println("isNotBlank = " + StringUtils.isNotBlank(" "));// isNotEmpty = trueSystem.out.println("isNotEmpty = " + StringUtils.isNotEmpty(" "));// isNumeric = falseSystem.out.println("isNumeric = " + StringUtils.isNumeric("12-3"));// join = 1;2;3System.out.println("join = " + StringUtils.join(Arrays.asList(1, 2, 3),";"));// lastIndexOf = 5System.out.println("lastIndexOf = " + StringUtils.lastIndexOf("sdfafvdsffs","v"));// left = abcSystem.out.println("left = " + StringUtils.left("abc", 4));// leftPad =**batSystem.out.println("leftPad = " + StringUtils.leftPad("bat", 5,"**"));// length = 6System.out.println("length = " + StringUtils.length("sdfdfs"));// mid = cSystem.out.println("mid = " + StringUtils.mid("abc", 2, 4));// 不知道System.out.println("abln = " + StringUtils.normalizeSpace("sdfs dsfs"));// ordinalIndexOf = 4System.out.println("ordinalIndexOf = " + StringUtils.ordinalIndexOf("aabaabaa", "ab", 2));// overlay = zzzzefSystem.out.println("overlay = " + StringUtils.overlay("abcdef", "zzzz", -1, 4));// prependIfMissing = xyzMNOabcSystem.out.println("prependIfMissing = " + StringUtils.prependIfMissing("MNOabc", "xyz", "mno"));// remove = qdSystem.out.println("remove = " + StringUtils.remove("queued", "ue"));// repeat = ababSystem.out.println("repeat = " + StringUtils.repeat("ab", 2));// replace = bSystem.out.println("replace = " + StringUtils.replace("aba", "a", ""));System.out.println("replace = " + StringUtils.replace("我给他批量添加了标签", "批量添加", "#"));// replaceAll = ABC_123System.out.println("replaceAll = " + StringUtils.replaceAll("ABCabc123", "[^A-Z0-9]+", "_"));// replaceChars = aycyaSystem.out.println("replaceChars = " + StringUtils.replaceChars("abcba", 'b', 'y'));// reverse = tabSystem.out.println("reverse = " + StringUtils.reverse("bat"));// reverseDelimited = c.b.aSystem.out.println("reverseDelimited = " + StringUtils.reverseDelimited("a.b.c", '.'));// split = {abc,def}String[] split = StringUtils.split("abc def");System.out.println("split = " + ArrayUtils.toString(split));// substring = cSystem.out.println("substring = " + StringUtils.substring("abc", 2));// swapCase = tHE DOG HAS A boneSystem.out.println("swapCase = " + StringUtils.swapCase("The dog has a BONE"));// trim = abcSystem.out.println("trim = " + StringUtils.trim(" abc "));// truncate = abcdefgSystem.out.println("truncate = " + StringUtils.truncate("abcdefg", 7));// wrapIfMissing = xabxSystem.out.println("wrapIfMissing = " + StringUtils.wrapIfMissing("ab", 'x'));
能看到这里,说明你多少有点无聊,划水摸鱼第一名就是你!!!