title: How to build a formatted string in Java?
body: <p>I am somewhat new to Java but I dislike the heavy use of string concatenation I'm seeing in my textbook.</p>
  
  <p>For example, I'd like to <strong>avoid</strong> doing this:</p>
  
  <pre><code>String s = "x:"+x+"," y:"+y+", z:"+z;
  </code></pre>
  
  <p>Is it possible to build a string using a notation similar to this:</p>
  
  <pre><code>String s = new String("x:%d, y:%d, z:%d", x, y, z);
  </code></pre>
  
  <h2>Input</h2>
  
  <pre><code>x = 1
  y = 2
  z = 3
  </code></pre>
  
  <h2>Output</h2>
  
  <pre><code>"x:1, y:2, z:3"
  </code></pre>
  
  <p>Note: I understand I can output formatted strings using <code>System.out.printf()</code> but I want to store the formatted string in a variable.</p>