title: The most sophisticated way for creating comma-separated Strings from a Collection/Array/List?
body: <p>During my work with databases I noticed that I write query strings and in this strings I have to put several restrictions in the where-clause from a list/array/collection. Should look like this:</p>
  
  <pre><code>select * from customer 
  where customer.id in (34, 26, ..., 2);
  </code></pre>
  
  <p>You can simplify this by reducing this to the question that you have collection of strings and want to create a comma-separated list of this strings in just one string.</p>
  
  <p>My approach I have used so far is something like that:</p>
  
  <pre><code>String result = "";
  boolean first = true;
  for(String string : collectionOfStrings) {
      if(first) {
          result+=string;
          first=false;
      } else {
          result+=","+string;
      }
  }
  </code></pre>
  
  <p>But this is as you can see very ugly. You cannot see what happens there on the first look, especially when the constructed strings (like every SQL query) is getting complicated.</p>
  
  <p>What is your (more) elegant way?</p>