apache commons下载地址
https://commons.apache.org/proper/commons-lang/
一般来说,String.replace 方法工作得很好,而且非常高效,特别是如果你使用的是Java 9。但是,如果应用程序需要大量的替换操作,并且你还没有更新到最新的Java版本,那么检查更快和更有效的替代方案仍然是有意义的。
一个候选就是 Apache Commons Lang’s StringUtils.replace 方法。正如Lukas Eder在他最近的一篇博客文章中所描述的那样,它大大超过了Java 8的String.replace 方法。
它只需要很小的改变。你只需要为Apache’s Commons Lang 项目增加一个Maven依赖项到你的应用pom.xml,并用StringUtils.replace方法替换所有String.replace方法的调用。
代码
// replace this
test.replace(“test”, “simple test”);
// with this
StringUtils.replace(test, “test”, “simple test”);
apache的replace,trim方法 StringUtils.replace(),StringUtils.trimWhitespace()
java原生的replace,trim方法之间性能的巨大差别。
原文地址:https://dzone.com/articles/11-simple-java-performance-tuning-tips
原文地址:http://www.iteye.com/topic/1114218
使用Apache Commons StringUtils.Replace 代替String.replace
猜你喜欢
转载自weilan62.iteye.com/blog/2399487
今日推荐
周排行