StringUtils 工具
<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'));
能看到这里,说明你多少有点无聊,划水摸鱼第一名就是你!!!
StringUtils 工具相关推荐
- Apache Commons包 StringUtils工具类深入整理(转载)
[转载地址]:cnblogs.com/sealy321/p/10227131.html 字符串是在程序开发中最常见的,Apache Commons开源项目在org.apache.commons.lan ...
- StringUtils 工具类常用方法汇总 1(判空、转换、移除、替换、反转)
Apache commons lang3 包下的 StringUtils 工具类中封装了一些字符串操作的方法,非常实用,使用起来也非常方便.最近自己也经常在项目中使用到了里面的一些方法,在这里将常用的 ...
- Apache Commons StringUtils工具类深入整理
字符串是在程序开发中最常见的,Apache Commons开源项目在org.apache.commons.lang3包下提供了StringUtils工具类,该类相当于是对jdk自带的String类的增 ...
- Apache commons lang3 StringUtils工具类
Apache commons lang3 StringUtils工具类 Apache commons lang3包下的StringUtils工具类中封装了一些字符串操作的方法,非常实用,使用起来也非常 ...
- StringUtils工具之StringUtils.isNotBlank()和StringUtils.isNotBlank()的区别
StringUtils工具之StringUtils.isNotBlank()和StringUtils.isNotBlank()的区别 学习笔记仅供参考: 1. StringUtils.isNotBla ...
- 利用StringUtils工具类进行String为空的判断
利用工具类进行String类型数据的非空判断,让自己的项目代码变得更加的简洁明了. 判断某字符串是否为空,为空的标准是 str==null 或 str.length()==0 下面是 String ...
- 学习StringUtils工具类
在JAVA中我们用的最多的类应该就是String了.对于String的处理说简单也简单,但是有的时候要自己去实现一些功能还是要浪费一点时间的.一年之前接触了StringUtils这个工具类,就猛然爱上 ...
- StringUtils工具类的常用方法
StringUtils 方法的操作对象是 java.lang.String 类型的对象,是对 JDK 提供的 String 类型操作方法的补充,并且是 null 安全的(即如果输入参数 String ...
- StringUtils工具类的isBlank()方法使用说明
在校验一个String类型的变量是否为空时,通常存在3中情况 是否为 null 是否为 "" 是否为空字符串(引号中间有空格) 如: " ". Str ...
- 判断String为空 StringUtils工具 isNotEmpty与isNotBlank区别
如何判断String是否为空? 判断Strings是否为空,很多人第一反应就是 str != null && str.length > 0.可能已经忘了StringUtils工具 ...
最新文章
- Android 保存崩溃日志到本地目录下
- android studio 去掉标题栏的简单方法
- 服务器用REG ECC内存的好处
- ad13批量安装元件库_ad16如何批量添加封装库?
- SpringMVC的数据响应-页面跳转-返回字符串形式(应用)
- 简明Vim练级攻略(转)
- android京东首页轮播代码,web移动端-轮播
- SharePoint学习札记[4] — 创建SharePoint站点
- 直播预告 | 视觉SLAM在AR应用上的关键性问题探讨
- javaweb工程中web.xml配置
- mysql 写入性能_MySQL存储写入性能严重抖动分析
- Python--文件修改
- (专升本)Internet(计算机网络系统)
- Qt 局域网聊天工具
- docker安装详细教程
- Redis安装部署(Windows/Linux)
- 新电商正面迎战“阅读焦虑”
- 路胜与阿斯利康达成战略合作;施乐辉携手镁信健康发布PICO;张云出任药研社首席运营官 | 医药健闻...
- 在南宁做网站找哪家好
- PCF8574AT驱动LCD1602
热门文章
- 教你看懂ACC、TJA、 ICA、ICC 这些功能都能干些啥
- 西门菲莎大学计算机专业怎么样,西蒙菲莎大学世界排名2021年
- 平分秋色? 鹿死谁手?
- [CF1603D]Artistic Partition
- 系统集成项目管理工程师高频考点(第一章)
- 电脑文件管理,教你一键将大量文件夹名称翻译成英文
- MountVolume.NewMounter initialization failed for volume “pvc-61dedc85-ea5a-4ac7-aaf3-e072e2e46e18“
- arduino点阵声音频谱_Arduino实现32分频音频频谱显示器
- 【dva】dva使用与实现(七)
- Windows下虚拟键盘鼠标(USB中文网)