將List元素拼裝成逗號分隔的字串

ZHOU_VIP發表於2017-06-22

/**
 * 將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);



相關文章