title: How to use String.format() in Java?
body: <p>I am a beginner in Java, and I'm using thenewboston's java tutorials (youtube). At tutorial 36-37 he starts using a String.format(); which he didn't explain in past tutorials. Here is the code for a class he was making:</p>
  
  <pre><code>    public class tuna {
          private int hour;
          private int minute;
          private int second;
  
          public void setTime(int h, int m, int s){
              hour = ((h &gt;= 0 &amp;&amp; h &lt; 24) ? h : 0);
              minute = ((m &gt;= 0 &amp;&amp; m &lt; 60) ? m : 0);
              second = ((s &gt;= 0 &amp;&amp; s &lt; 60) ? s : 0);
          }
  
          public String toMilitary(){
              return String.format("%02d:%02d:%02d", hour, minute, second);
          }
      }
  </code></pre>
  
  <p>So what he's doing is he's doing some sort of military time class and using String formatting. So what I'm asking is if someone can explain to me how String.format() works and how the formatting above works. Thanks for the help!</p>