public static < T > String joinAnd ( final String delimiter , final String lastDelimiter , final Collection < T > objs ) { if ( objs == null || objs . isEmpty ( ) ) { return "" ; } final Iterator < T > iter = objs . iterator ( ) ; final StringBuffer buffer = new StringBuffer ( Strings . toString ( iter . next ( ) ) ) ; int i = 1 ; while ( iter . hasNext ( ) ) { final T obj = iter . next ( ) ; if ( notEmpty ( obj ) ) { buffer . append ( ++ i == objs . size ( ) ? lastDelimiter : delimiter ) . append ( Strings . toString ( obj ) ) ; } } return buffer . toString ( ) ; }
Like join but allows for a distinct final delimiter . For english sentences such as Alice Bob and Charlie use and and as the delimiters .