title: Java - Printing commas in a loop
body: <p>I'm running into this problem where if want to loop through an array and print out its contents separated by a comma, it prints out an extra at the end.
  I did some searching but, couldn't find an answer that worked for this situation.</p>
  
  <p>Code: </p>
  
  <pre><code>public String toString(){
  
      String hold= "";
      for(int i = 0; i &lt; array.length; i ++){
  
          if(array[i] == true){
              hold + = i;
              if(i != array.length-1)
                  hold+= ",";
          }
      }
      return hold;
  }
  </code></pre>