title: How to format a string passing a constant variable as length width?
body: <p>I'm learning Java so maybe this is a silly question, but here it is. I know that a <code>String</code> variable can be formatted in java using the <code>.format</code> method:</p>
  
  <pre><code>String.format("|%20s|", "Hello world");
  
  &gt;&gt;|         Hello world|
  </code></pre>
  
  <p>But how can i specify the width using a variable? I.e, instead of typing the litteral '20':</p>
  
  <pre><code>String.format("|%MY_VARs|", "Hello world"); //&lt;-- how to put MY_VAR inside?
  </code></pre>