title: Fastest way to perform a lot of strings replace in Java
body: <p>I have to write some sort of parser that get a String and replace certain sets of character with others. The code looks like this:</p>
  
  <pre><code>noHTMLString = noHTMLString.replaceAll("&lt;/p&gt;", "\n");
  noHTMLString = noHTMLString.replaceAll("&lt;br/&gt;", "\n\n");
  noHTMLString = noHTMLString.replaceAll("&lt;br /&gt;", "\n\n");
  //here goes A LOT of lines like these ones
  </code></pre>
  
  <p>The function is very long and performs a lot of strings replaces. The issue here is that it takes a lot of time because the method it's called a lot of times, slowing down the application performance.</p>
  
  <p>I have read some threads here about using StringBuilder as an alternative but it lacks the ReplaceAll method and as it's noted here <a href="https://stackoverflow.com/questions/1250216/does-string-replaceall-performance-suffer-from-string-immutability">Does string.replaceAll() performance suffer from string immutability?</a> the replaceAll method in String class works with </p>
  
  <blockquote>
    <p>Match Pattern &amp; Matcher and Matcher.replaceAll() uses a StringBuilder to store the eventually returned value
    so I don't know if switching to StringBuilder will really reduce the time to perform the substitutions.</p>
  </blockquote>
  
  <p>Do you know a fast way to do a lot of String replace in a fast way? Do you have any advice for this problem?</p>
  
  <p>Thanks.</p>
  
  <p><strong>EDIT</strong>: I have to create a report that have a few fields with html text. For each row I'm calling the method that replaces all the html tags and special characters inside these strings. With a full report it takes more than 3 minutes to parse all the text. The problem is that I have to invoke the method very often</p>