这应该是一个简单的。如果长度大于1,我需要格式化一个字符串数组,如下所示:“('STRING','STRING')
感谢名单
if (form.getSorCodes().length > 1)
for( int i=0;i<form.getSorCodes().length;i++)
{
//format here
}
答案 0 :(得分:5)
String[] sorCodes = form.getSorCodes();
if (sorCodes.length > 1) {
StringBuilder builder = new StringBuilder("(");
for( int i=0;i<sorCodes.length;i++) {
builder.append("'").append(sorCodes[i]).append("'");
if(i < sorCodes.length - 1) {
builder.append(",");
}
}
builder.append(")");
builder.toString(); //('STRING','STRING')
}
答案 1 :(得分:0)
使用Guava:
StringBuilder result = new StringBuilder("(");
Joiner.on(',').appendTo(result, stringArray);
return result.append(",").toString();
答案 2 :(得分:0)
只需使用此类:
StringBuilder result = new StringBuilder();