/**
* 将List元素拼装成逗号分隔的字符串
*/
public static String list2String(List<String> arr){
StringBuilder sb = new StringBuilder();
for(Object obj : arr){
sb.append(obj).append(",");
}
return sb.deleteCharAt(sb.length() - 1).toString();
}
public StringBuilder deleteCharAt(int index) {
super.deleteCharAt(index);
return this;
}
public AbstractStringBuilder deleteCharAt(int index) {
if ((index < 0) || (index >= count))
throw new StringIndexOutOfBoundsException(index);
System.arraycopy(value, index+1, value, index, count-index-1);
count--;
return this;
}
public static native void arraycopy(Object src,int srcPos,Object dest,int destPos,int length);
将List元素拼装成逗号分隔的字符串
最新推荐文章于 2024-04-12 09:30:02 发布
本文介绍了一种将List集合中的元素转换为逗号分隔的字符串的方法,并提供了具体的Java实现代码。该方法首先使用StringBuilder来构建字符串,然后遍历List中的每个元素并附加到StringBuilder上,最后移除最后一个多余的逗号。
1万+

被折叠的 条评论
为什么被折叠?



