我想去掉最后一个数据中的逗号。
示例:
我有以下代码:
StringBuilder temp = new StringBuilder();
for (int i=0; i<allLines.size(); i++){
StringBuilder temp2 = new StringBuilder();
String[] abc = line.split("\t");
temp2.append("{");
temp2.append("id: \""+abc[0]+"\",");
temp2.append("name: \""+abc[1]+"\",");
temp2.append("},");
temp.append(temp2.toString());
}
System.out.println("result : "+temp.toString());
ihave code and result:
{id: "1", name: "Jhames"},{id: "2", name: "Richard"},
但我想要结果:
{id: "1", name: "Jhames"},{id: "2", name: "Richard"}
stringBuilder.append("foo" + x)
,因为由于串联,此代码与stringBuilder.append(new StringBuilder("foo).append(x).toString())
相同,因此可以看出它有点否定了拥有stringBuilder
的目的。相反,请使用stringBuilder.append("foo").append(x)
。 - Pshemo