public static String join(Collection<String> parts, String separator,String lastSeparator) {StringBuilder sb = new StringBuilder();int i = 0;int lastIndex = parts.size() - 1;for (String part : parts) {sb.append(part);if (i == lastIndex - 1) {sb.append(lastSeparator);} else if (i != lastIndex) {sb.append(separator);}i++;}return sb.toString();}

public static String join ( Collection < String > parts , String separator , String lastSeparator ) { StringBuilder sb = new StringBuilder ( ) ; int i = 0 ; int lastIndex = parts . size ( ) - 1 ; for ( String part : parts ) { sb . append ( part ) ; if ( i == lastIndex - 1 ) { sb . append ( lastSeparator ) ; } else if ( i != lastIndex ) { sb . append ( separator ) ; } i ++ ; } return sb . toString ( ) ; }
public static string Join(ICollection<string> parts, string separator, string lastSeparator){StringBuilder sb = new StringBuilder();int i = 0;int lastIndex = parts.Count - 1;foreach (string part in parts){sb.Append(part);if (i == lastIndex - 1){sb.Append(lastSeparator);}else{if (i != lastIndex){sb.Append(separator);}}i++;}return sb.ToString();}
