public static String join ( final List < String > list ) { // zero, empty or one element if ( list == null ) { return null ; } else if ( list . size ( ) == 0 ) { return "" ; } else if ( list . size ( ) == 1 ) { return list . get ( 0 ) ; } // two or more elements final StringBuilder builder = new StringBuilder ( ) ; for ( String item : list ) { if ( builder . length ( ) > 0 ) { builder . append ( ", " ) ; } builder . append ( item ) ; } return builder . toString ( ) ; }
Joins items of a text list separating items by comma .