title: How to format an array with printf() in Java?
body: <p>I know how to format single variables, but I do not know how to format an array with <code>printf()</code>. I want to display my program with each number lining up with each other vertically, with each number on each line with the same amount of spaces. Below is an example of what I mean with different numbers:</p>
  
  <pre><code>1.1   2.2   3.3   4.4   5.5
  1     2     3     4     5
  </code></pre>
  
  <p>Here is the code that I have for trying to display the numbers:</p>
  
  <pre><code> // create array
   String[] tempsArray2 = temps2.toArray(new String[0]);
  
   // for-each loop
   for(String ss : tempsArray2){
  
       // display ss to make sure program works correctly
       System.out.printf("%40s", ss);
  </code></pre>
  
  <p>When I run it, the program displays like this:</p>
  
  <pre><code>run:
  70.3   70.8   73.8   77.0   80.7   83.4   84.5   84.4   83.4   80.2   76.3   72.0   
       69 67 66 64 66 69 67 67 70 69 69 70BUILD SUCCESSFUL (total time: 0 seconds)
  </code></pre>
  
  <p>How can I fix this so that I can format the whole array once with a single <code>System.out.printf();</code> statement, or do I have to format them one by one? Any help will be greatly appreciated.</p>