title: Iterating a list of Strings in Java
body: <p>I'm iterating through a list of list of strings. I need to print each list in comma separated format except the last element. This is my code.</p>
  
  <pre><code>for(Iterator itr = list.iterator(); itr.hasNext();){
      List&lt;String&gt; l = (List&lt;String&gt;) itr.next();
      for(Iterator it = l.iterator(); it.hasNext();){
         System.out.print(it.next() + " ");
      }
      System.out.println();
  }
  </code></pre>
  
  <p>This prints something like </p>
  
  <pre><code>listen, silent, tinsel,
  </code></pre>
  
  <p>How do I format the print logic to remove the comma after the last element. I can do that on <code>for i</code> loop checking the value of <code>i</code> against the last index, but wish to know how to do it with an <code>Iterator</code> in Java.</p>