在Java中构建分隔项字符串的最佳方法是什么?
public String appendWithDelimiter( String original, String addition, String delimiter ) { if ( original.equals( "" ) ) { return addition; } else { return original + delimiter + addition; }}String parameterString = "";if ( condition ) parameterString = appendWithDelimiter( parameterString, "elementName", "," );if ( anotherCondition ) parameterString = appendWithDelimiter( parameterString, "anotherElementName", "," );
parameterArray = [];parameterArray << "elementName" if condition;parameterArray << "anotherElementName" if anotherCondition;parameterString = parameterArray.join(",");
红糖糍粑
慕仙森
慕斯709654
相关分类