public static String join(Collection<?> c,String delim){
  StringBuilder retval=new StringBuilder();
  Iterator<?> itr=c.iterator();
  if (itr.hasNext())   retval.append(itr.next());
 else   return "";
  while (itr.hasNext()) {
    retval.append(delim);
    retval.append(itr.next());
  }
  return retval.toString();
}

public static String join ( Collection < ? > c , String delim ) { StringBuilder retval = new StringBuilder ( ) ; Iterator < ? > itr = c . iterator ( ) ; if ( itr . hasNext ( ) ) retval . append ( itr . next ( ) ) ; else return "" ; while ( itr . hasNext ( ) ) { retval . append ( delim ) ; retval . append ( itr . next ( ) ) ; } return retval . toString ( ) ; }
similar to perl ' s join ( ) method on lists , but works with all collections .
