I want to join strings together, but when doing this it often happens that there is a comma too muchmany, and therefore I need to remove that comma. In the belowthis code, I use the substring to delete the two last characters.
Is there aHow can this become more elegant way to solve this problem?
List<String> paramList = new ArrayList<String>( ); paramList.add( "param1" ); paramList.add( "param2" ); StringBuilder result = new StringBuilder(); for ( String p : paramList ) { result.append( p ).append( ", " ); } String withoutLastComma = result.substring( 0, result.length( ) - ", ".length( ) ); System.err.println( withoutLastComma );