List<String> solList = new ArrayList<String>( );
solList.add( "num1" );
solList.add( "num2" );
StringBuilder result = new StringBuilder();
for ( String a : solList )
{
result.append( a ).append( ", " );
}
String withoutLastComma = result.substring( 0, result.length( ) - ",
".length( ) );
System.err.println( withoutLastComma );
I want remove last comma,I use substring,how can I become better this code?
use string utility methods such as "StringUtil.join" to concatenate elements in an array or a collection object. Consult the "StringUtil API's StringUtil.join" entry.
For example:
StringUtils.join(["e", "f", "g"], "--") // => "e--f--g