如下是通过位置去删除固定的字符
String str[] = { "hello", "beijing", "world", "shenzhen" };
StringBuffer buf = new StringBuffer();
for (int i = 0; i < str.length; i++) {
buf.append(str[i]).append(",");
}
if (buf.length() > 0) {
//方法一 : substring
System.out.println(buf.substring(0, buf.length()-1));
//方法二 :replace
System.out.println(buf.replace(buf.length() - 1, buf.length(), ""));
//方法三: deleteCharAt
System.out.println(buf.deleteCharAt(buf.length()-1));
}
当然也可以直接删除某个已知的字符,比如逗号,把逗号替换为空
//方法 :replace
System.out.println(buf.replace(",",""));