title: Save for loop result as string
body: <pre><code>    String input[] = request.getParameterValues("checkbox");
  
          for(int i=0;i&lt;input.length;i++) {
              if (i==input.length-1) {
                  System.out.print(input[i]+" ");
              } else {
                      System.out.print(input[i]+", ");
              }
          }
  </code></pre>
  
  <p>The result is that i print to console something like "CustomerId, FirstName, LastName, Phone".
  I want to save the result of the for loop as a string variable instead, so then i can do</p>
  
  <pre><code>     String query = "select "+result above+" from table";
  </code></pre>
  
  <p>How to do it?</p>