Use Apache Commons StringUtils.Replace instead of String.replace

apache commons download link
https://commons.apache.org/proper/commons-lang/

In general, String.replace method works well and is very efficient, especially if you are using Java 9. However, if the application requires a lot of replacement operations, and you haven't updated to the latest Java version, it still makes sense to check for faster and more efficient alternatives.

One candidate is Apache Commons Lang's StringUtils.replace method. As Lukas Eder described in one of his recent blog posts, it greatly surpasses Java 8's String.replace method.

It only needs minor changes. You just need to add a Maven dependency for Apache's Commons Lang project to your application pom.xml and replace all String.replace method calls with StringUtils.replace method.
Code
// replace this 
test.replace("test", "simple test"); 
// with this 
StringUtils.replace(test, "test", "simple test"); 

apache's replace, trim method StringUtils.replace() , StringUtils.trimWhitespace()

Java's native replace, the huge difference in performance between trim methods.

Original address: https://dzone.com/articles/11-simple-java-performance-tuning-tips
Original address: http://www.iteye.com/topic/1114218

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326611133&siteId=291194637