将集合转换成指定分隔符和前后缀的字符串

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public static String collectionToDelimitedString(Collection<?> coll, String delim, String prefix, String suffix) {
    if (CollectionUtils.isEmpty(coll)) {
        return "";
    }
    StringBuilder sb = new StringBuilder();
    Iterator it = coll.iterator();
    while (it.hasNext()) {
        sb.append(prefix).append(it.next()).append(suffix);
        if (it.hasNext())
            ;
        sb.append(delim);
    }
 
    return sb.toString();
}

  

posted @   GrandKai  阅读(684)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示