title: How do I properly align using String.format in Java?
body: <p>Let's say I have a couple variable and I want to format them so they're all aligned, but the variables are different lengths. For example:</p>
  
  <pre><code>String a = "abcdef";
  String b = "abcdefhijk";
  </code></pre>
  
  <p>And I also have a price.</p>
  
  <pre><code>double price = 4.56;
  </code></pre>
  
  <p>How would I be able to format it so no matter how long the String is, they are aligned either way? </p>
  
  <pre><code>System.out.format("%5s %10.2f", a, price);
  System.out.format("%5s %10.2f", b, price);
  </code></pre>
  
  <p>For example, the code above would output something like this: </p>
  
  <pre><code>abcdef       4.56
  abcdefhijk       4.56
  </code></pre>
  
  <p>But I want it to output something like this:</p>
  
  <pre><code>abcdef      4.56
  abcdefhijk  4.56
  </code></pre>
  
  <p>How would I go about doing so? Thanks in advance.</p>