public static String join ( Collection < ? > collection , String delimiter ) { if ( collection == null || collection . isEmpty ( ) ) { return EMPTY_STRING ; } else if ( delimiter == null ) { delimiter = EMPTY_STRING ; } StringBuilder builder = new StringBuilder ( ) ; Iterator < ? > it = collection . iterator ( ) ; while ( it . hasNext ( ) ) { builder . append ( it . next ( ) ) . append ( delimiter ) ; } int length = builder . length ( ) ; builder . delete ( length - delimiter . length ( ) , length ) ; return builder . toString ( ) ; }
Joins a Collection of typed objects using their toString method separated by delimiter