public static String join(final Iterator<?> iterator,final String separator){
  if (iterator == null) {
    return null;
  }
  if (!iterator.hasNext()) {
    return "";
  }
  final Object first=iterator.next();
  if (!iterator.hasNext()) {
    return first == null ? null : first.toString();
  }
  final StringBuilder buf=new StringBuilder(256);
  if (first != null) {
    buf.append(first);
  }
  while (iterator.hasNext()) {
    if (separator != null) {
      buf.append(separator);
    }
    final Object obj=iterator.next();
    if (obj != null) {
      buf.append(obj);
    }
  }
  return buf.toString();
}

public static String join ( final Iterator < ? > iterator , final String separator ) { if ( iterator == null ) { return null ; } if ( ! iterator . hasNext ( ) ) { return "" ; } final Object first = iterator . next ( ) ; if ( ! iterator . hasNext ( ) ) { return first == null ? null : first . toString ( ) ; } final StringBuilder buf = new StringBuilder ( 256 ) ; if ( first != null ) { buf . append ( first ) ; } while ( iterator . hasNext ( ) ) { if ( separator != null ) { buf . append ( separator ) ; } final Object obj = iterator . next ( ) ; if ( obj != null ) { buf . append ( obj ) ; } } return buf . toString ( ) ; }
copied fom commons stringutils
