public static String join ( Collection < String > toJoin , String separator ) { if ( isNullOrEmpty ( toJoin ) ) { return "" ; } StringBuilder joinedString = new StringBuilder ( ) ; int currentIndex = 0 ; for ( String s : toJoin ) { if ( s != null ) { joinedString . append ( s ) ; } if ( currentIndex ++ != toJoin . size ( ) - 1 ) { joinedString . append ( separator ) ; } } return joinedString . toString ( ) ; }
Joins a collection of strings with the given separator into a single string .