title: Replace all occurrences of substring in a string - which is more efficient in Java?
body: <p>I know of two ways of replacing <em>all</em> occurrences of substring in a string.</p>
  
  <p>The regex way (assuming "substring-to-be-replaced" doesn't include regex special chars):</p>
  
  <pre><code>String regex = "substring-to-be-replaced" + "+";
  Pattern scriptPattern = Pattern.compile(regex);
  Matcher matcher = scriptPattern.matcher(originalstring);
  newstring = matcher.replaceAll("replacement-substring");
  </code></pre>
  
  <p>The String.replace() way:</p>
  
  <pre><code>newstring = originalstring.replace("substring-to-be-replaced", "replacement-substring");
  </code></pre>
  
  <p>Which of the two is more efficient (and why)?</p>
  
  <p>Are there more efficient ways than the above described two?</p>