title: Should I use Java's String.format() if performance is important?
body: <p>We have to build Strings all the time for log output and so on. Over the JDK versions we have learned when to use <code>StringBuffer</code> (many appends, thread safe) and <code>StringBuilder</code> (many appends, non-thread-safe).</p>
  
  <p>What's the advice on using <code>String.format()</code>? Is it efficient, or are we forced to stick with concatenation for one-liners where performance is important?</p>
  
  <p>e.g. ugly old style,</p>
  
  <pre><code>String s = "What do you get if you multiply " + varSix + " by " + varNine + "?";
  </code></pre>
  
  <p>vs. tidy new style (String.format, which is possibly slower),</p>
  
  <pre><code>String s = String.format("What do you get if you multiply %d by %d?", varSix, varNine);
  </code></pre>
  
  <p>Note: my specific use case is the hundreds of 'one-liner' log strings throughout my code. They don't involve a loop, so <code>StringBuilder</code> is too heavyweight. I'm interested in <code>String.format()</code> specifically.</p>