title: Remove the delimiter , at the end
body: <pre><code>String prefix = "";
  for (String serverId : serverIds) {
    sb.append(prefix);
    prefix = ",";
    sb.append(serverId);
  }
  </code></pre>
  
  <p>The following code runs faster than the above code . the "," prefix object does unnecessary object creation on every iteration . The above code takes 86324 nano seconds,while mine takes only 68165 nano seconds.</p>
  
  <pre><code>List&lt;String&gt; l =  Arrays.asList("SURESH1","SURESH2","SURESH4","SURESH5");
  StringBuffer  l1 = new StringBuffer();
  int sz = l.size(); 
  int i=0; long t =
  System.nanoTime();
  for (String s : l)
  { 
     l1.append(s);     
     if  ( i != sz-1)
          l1.append(",");   i++;
     } 
  } 
  long t2 = System.nanoTime();
  System.out.println ((t2-t)); System.out.println(l1);
  
  // The time taken for the above code is 68165 nano seconds
  SURESH1,SURESH2,SURESH4,SURESH5
  </code></pre>
  
  <p>kindly let me know which one is better in ur view.</p>