/**
*
* 第一种, 用stringbuffer
*/
List<String> list = new ArrayList<String>();
list.add("a");
list.add("b");
list.add("c");
StringBuffer sb = new StringBuffer();
for (String str : list) {
if (sb.length() != 0) {
sb.append(",");
}
sb.append(str);
}
System.out.println(sb);
/**
*
* 第二种, 不用stringbuffer,用字符串
*/
String line = "";
for (int i = 0; i < list.size(); i++) {
if ((line.length() != 0)) {
line += ",";
}
line += list.get(i);
}
System.out.println(line);